VBA IF Loop Help

bdkrame

New Member
Joined
Aug 26, 2015
Messages
9
I'm having a bit of trouble with a macro. The code is supposed to first check to see if a certain parameter called 'Setup' is True or False and then checks each sheet for the value of R43 if 'Setup' is True or R44 if 'Setup' is False. If the value in R43 or R44 is True the code highlights a cell on a different tab called 'Input' green, or red if the value is False. This is done for different cells corresponding to each worksheet checked. Below is my code.

Code:
Sub Tab_Change(sheet As String)
' The sheet name is provided by the calling macro on each sheet.
'   Determines if in setup mode or not.
    If Worksheets("Input").Setup.Value = True Then
        If Worksheets(sheet).Range("r43").Value = True Then
            green (sheet)
        Else
            Red (sheet)
        End If
    Else
        If Worksheets(sheet).Range("r44").Value = True Then
            green (sheet)
        Else
            Red (sheet)
        End If
    End If


End Sub


Sub Red(sheet As String)
    Dim changedcell As String
    changedcell = sheet + "cell"


    'Sets sheet indicator to Red
    'Worksheets("Input").Shapes(sheet).Fill.ForeColor.RGB = RGB(255, 0, 0)
    Worksheets("Input").Range(changedcell) = False


End Sub


Sub green(sheet As String)
    Dim changedcell As String
    changedcell = sheet + "cell"


    'Sets sheet indicator to Green
    'Worksheets("Input").Shapes(sheet).Fill.ForeColor.RGB = RGB(0, 128, 0)
    Worksheets("Input").Range(changedcell) = True


End Sub

My problem is that if R43 is TRUE and R44 is FALSE and the Setup.Value = TRUE, I should be checking R43 and coloring my cell green but for some reason I am seeing red. It seems like the code is looking at cell R44 and seeing the FALSE value, but I can't understand why. Anybody have any ideas?
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
That turned all of my cells red. I took out the second if loop that checks R44 and it correctly colors the cell according to the value of R43. As soon as I add it back in it changes the result. Is the code executing both halves of my overall if loop? That would make the error I'm seeing make sense, but I don't see why it would do that.
 
Upvote 0
Neither the ObjectBrowser nor Microsoft's Development website show a .SetUp property for a worksheet object.

What is the .SetUp property that you are testing for?
 
Upvote 0

Forum statistics

Threads
1,223,236
Messages
6,170,917
Members
452,366
Latest member
TePunaBloke

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