2

I'm very new to programming (1 day experience) and I am trying to build an interactive database but I keep running into issues with having a certain part work.

I want Excel to read the value selected in a certain cell and based on the value in that cell then have it open to a separate sheet, where I can begin another set of data entry.

I have tried a number of different options but as of now, my code looks like this:

Dim inputWks As Worksheet
Set inputWks = ("Input")

With inputWks
    If Range("D13").contents = "Yes" Then
        ActiveWorkbook.Sheets("Sheets2").activate
    End If
End With

I know this is a simple question but I have not been able to have this work..

  • As long as you are just getting started, you may want to review [How to avoid using Select in Excel VBA macros](http://stackoverflow.com/questions/10714251/how-to-avoid-using-select-in-excel-vba-macros) for methods on getting away from relying on select and activate to accomplish your goals. –  May 25 '15 at 19:10
  • I will definitely look into that. Thanks! – Chris Williamson May 25 '15 at 19:22

1 Answers1

0

try this

Sub DoIt()
    Dim inputWks As Worksheet
    Set inputWks = ActiveWorkbook.Sheets("Input")

    With inputWks
        If Range("D13").Cells(1, 1) = "Yes" Then
           ActiveWorkbook.Sheets("Sheets2").Activate
        End If 
    End With 
End Sub
OlimilOops
  • 6,747
  • 6
  • 26
  • 36
  • Might be missing a `.` in `.Range("D13").Cells(1, 1)`. –  May 25 '15 at 19:09
  • This is still not working for me for some reason. I think that the code is running because there is no error messaging be brought up though. I cant link the full code but I got it http://www.contextures.com/exceldataentryupdateform.html in case anyone is interested. Credit to www.contextures.com for the model! – Chris Williamson May 25 '15 at 19:29
  • Try it with a period in front of `.Range("D13")`. The period mean that the parent worksheet is the one specified in the With statement (e.g. the worksheet named **Input**). –  May 25 '15 at 19:31
  • By default, VBA is also case-sensitive in text comparisons and a leading or trailing space will invalidate the text comparison. –  May 25 '15 at 19:33
  • This also doesn't seem to be the issue. There is nothing on the sheet, could that be part of the problem? – Chris Williamson May 25 '15 at 19:37