If/then Statements based on cell value

mjm7930

New Member
Joined
Aug 3, 2010
Messages
12
I'm trying to run a macro based on whether a cell value is "1", "2", etc. I have a set of ComboBoxes and a Command Button. Once the Command Button is clicked, a set of data will be graphed based on what the ComboBoxes select.

I'm not sure if I have my if/then statements right. Specifically, what I want the code to do is, for example, if cell D5 is "1" and cell "G5" is "1", a set of data will be graphed. So there are 2 if/then statements.

D5 can be a number 1-6, and G5 can be a number 1-2.

The graph is automatically set up; it just needs the values to be pasted in its specific range. However, nothing ever gets pasted, so the graph doesn't generate. Any help? Thanks!

Here's what I have below..
Code:
If (D5 = "1") Then
    If (G5 = "1") Then
        Sheets("Graph Data").Select
        ActiveWindow.SmallScroll Down:=-15
        Range("A2:H200").Select
        Selection.ClearContents
        Range("J4").Select
        Sheets("Raw Data").Select
        Range("A11:D73").Select
        Selection.Copy
        Sheets("Graph Data").Select
        Range("A2").Select
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
        Range("L33").Select
    ElseIf (G5 = "2") Then
        Sheets("Graph Data").Select
        ActiveWindow.SmallScroll Down:=-15
        Range("A2:H200").Select
        Selection.ClearContents
        Range("J4").Select
        Sheets("Raw Data").Select
        Range("E11:H71").Select
        Selection.Copy
        Sheets("Graph Data").Select
        Range("A2").Select
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
            :=False, Transpose:=False
        Range("L33").Select
    End If
 

Some videos you may like

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.

mjm7930

New Member
Joined
Aug 3, 2010
Messages
12
Anyone think they can help? I've tried a few more things but still doesn't work..
 

benjicat

New Member
Joined
Jul 13, 2010
Messages
22
Could it be that the 1 and 2 are numbers rather than text? Perhaps...

Code:
If (D5 = 1) Then
    If (G5 = 1) Then
        Sheets("Graph Data").Select
        ActiveWindow.SmallScroll Down:=-15
        Range("A2:H200").Select
        Selection.ClearContents
        Range("J4").Select
        Sheets("Raw Data").Select
        Range("A11:D73").Select
        Selection.Copy
        Sheets("Graph Data").Select
        Range("A2").Select
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
        Range("L33").Select
    ElseIf (G5 = 2) Then
        Sheets("Graph Data").Select
        ActiveWindow.SmallScroll Down:=-15
        Range("A2:H200").Select
        Selection.ClearContents
        Range("J4").Select
        Sheets("Raw Data").Select
        Range("E11:H71").Select
        Selection.Copy
        Sheets("Graph Data").Select
        Range("A2").Select
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
            :=False, Transpose:=False
        Range("L33").Select
    End If
 

mjm7930

New Member
Joined
Aug 3, 2010
Messages
12
Thanks for the response! I tried that and it makes sense, but it still isn't working.. is something like this even possible? I would think it is.. can anyone please help?
 

Subscribe on YouTube

Watch MrExcel Video

Forum statistics

Threads
1,106,774
Messages
5,513,357
Members
408,948
Latest member
robertjohn18

This Week's Hot Topics

  • Sort code advice please
    Hi, I have the code below which im trying to edit but getting a little stuck. This was the original code which worked fine,columns A-F would sort...
  • SUMPRODUCT with nested If statement
    Hi everyone, Hope you're all well. I'm hoping someone will be able to point me in the right direction with a problem I'm having with a SUMPRODUCT...
  • VBA - simple sort is killing me!
    Hello all! This should be so easy, but not for me, apparently! I have a table of data that can be of varying lengths and widths. My current macro...
  • Compare Two Lists
    I have two Lists and I need to be able to Identify differences between them. List 100 comes from a workbook - the other is downloaded form the...
  • Formula that deducts points for each code I input.
    I am trying to create a formula that will have each student in my class start at 100 points and then for each code that I enter (PP for Poor...
  • Conditional formatting formula required for day of week and a value
    Hi, I have a really simple spreadsheet where column A is the date, column B is the activity total shown as a number and column C states the day of...
Top