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
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).

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?
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,163,400
Messages
5,831,411
Members
430,066
Latest member
rajd72

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top