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

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
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
 
Upvote 0
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?
 
Upvote 0

Forum statistics

Threads
1,214,646
Messages
6,120,720
Members
448,986
Latest member
andreguerra

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
Back
Top