IF Statement Not Being Recognized When True

Ark68

Well-known Member
Joined
Mar 23, 2004
Messages
4,564
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Please consider this code found in one of my worksheet (ws_form) module, in particular the code in blue.
Consider this example:
segtar is a range with address $R$31
rwend = 27
ws_form = worksheets("Form"), the module in which this code resides

I am unable to get the code to recognize the IF criteria of the blue code ...
If the segtar address = .Range("R" & rwend + 4) .... R31 = .range then proceed with that code...
R31 = .range("R31")

This is true, but it skips right over that IF as if it were false.

Thoughts?

Rich (BB code):
If Not Intersect(Target, .Range("R" & rwend + 3 & ":R" & rwend + 7)) Is Nothing Then
                .Unprotect
                'unselected to selected state
                If segtar.Cells.Interior.ColorIndex = xlNone Then
                Stop
                    segtar.Cells.Interior.Color = ccgreen
                    optn = segtar.Offset(, 1)
                    cntoperations = cntoperations + 1
                    
                    If segtar.Address = .Range("R" & rwend + 3) Then 'full plow
                        If .Range("R" & rwend + 4).Interior.Color = ccgreen Then 'SPOT PLOW
                            .Range("R" & rwend + 4).Interior.ColorIndex = xlNone
                            cntoperations = cntoperations - 1
                        End If
                        If .Range("R" & rwend + 6).Interior.Color = ccgreen Then 'FULL BLOW
                            .Range("R" & rwend + 6).Interior.ColorIndex = xlNone
                            cntoperations = cntoperations - 1
                        End If
                        If .Range("R" & rwend + 7).Interior.Color = ccgreen Then 'SPOT BLOW
                            .Range("R" & rwend + 7).Interior.ColorIndex = xlNone
                            cntoperations = cntoperations - 1
                        End If
                        If .Range("R" & rwend + 8).Interior.Color = ccgreen Then 'WIDEN BLOWER
                            .Range("R" & rwend + 8).Interior.ColorIndex = xlNone
                            cntoperations = cntoperations - 1
                        End If
                        If .Range("AB" & rwend + 3).Interior.Color = ccgreen Then 'PATROL
                            .Range("AB" & rwend + 3).Interior.ColorIndex = xlNone
                            cntoperations = cntoperations - 1
                        End If
                        
                    ElseIf segtar.Address = .Range("R" & rwend + 4) Then 'spot plow
                        If .Range("R" & rwend + 3).Interior.Color = ccgreen Then 'FULL PLOW
                            .Range("R" & rwend + 3).Interior.ColorIndex = xlNone
                            cntoperations = cntoperations - 1
                        End If
                        If .Range("R" & rwend + 6).Interior.Color = ccgreen Then 'FULL BLOW
                            .Range("R" & rwend + 6).Interior.ColorIndex = xlNone
                            cntoperations = cntoperations - 1
                        End If
                        If .Range("R" & rwend + 7).Interior.Color = ccgreen Then 'SPOT BLOW
                            .Range("R" & rwend + 7).Interior.ColorIndex = xlNone
                            cntoperations = cntoperations - 1
                        End If
                        If .Range("R" & rwend + 8).Interior.Color = ccgreen Then 'WIDEN BLOWER
                            .Range("R" & rwend + 8).Interior.ColorIndex = xlNone
                            cntoperations = cntoperations - 1
                        End If
                        If .Range("AB" & rwend + 3).Interior.Color = ccgreen Then 'PATROL
                            .Range("AB" & rwend + 3).Interior.ColorIndex = xlNone
                            cntoperations = cntoperations - 1
                        End If
                        
                    ElseIf segtar.Address = .Range("R" & rwend + 5) Then 'widen - plow
                        If .Range("R" & rwend + 6).Interior.Color = ccgreen Then 'FULL BLOW
                            .Range("R" & rwend + 6).Interior.ColorIndex = xlNone
                            cntoperations = cntoperations - 1
                        End If
                        If .Range("R" & rwend + 7).Interior.Color = ccgreen Then 'SPOT BLOW
                            .Range("R" & rwend + 7).Interior.ColorIndex = xlNone
                            cntoperations = cntoperations - 1
                        End If
                        If .Range("R" & rwend + 8).Interior.Color = ccgreen Then 'WIDEN BLOWER
                            .Range("R" & rwend + 8).Interior.ColorIndex = xlNone
                            cntoperations = cntoperations - 1
                        End If
                        If .Range("AB" & rwend + 3).Interior.Color = ccgreen Then 'PATROL
                            .Range("AB" & rwend + 3).Interior.ColorIndex = xlNone
                            cntoperations = cntoperations - 1
                        End If
                    
                    ElseIf segtar.Address = .Range("R" & rwend + 6) Then 'full blow
                        If .Range("R" & rwend + 3).Interior.Color = ccgreen Then 'full plow
                            .Range("R" & rwend + 3).Interior.ColorIndex = xlNone
                            cntoperations = cntoperations - 1
                        End If
                        If .Range("R" & rwend + 4).Interior.Color = ccgreen Then 'spot plow
                            .Range("R" & rwend + 4).Interior.ColorIndex = xlNone
                            cntoperations = cntoperations - 1
                        End If
                        If .Range("R" & rwend + 5).Interior.Color = ccgreen Then 'widen plow
                            .Range("R" & rwend + 5).Interior.ColorIndex = xlNone
                            cntoperations = cntoperations - 1
                        End If
                        If .Range("R" & rwend + 7).Interior.Color = ccgreen Then 'spot blow
                            .Range("R" & rwend + 7).Interior.ColorIndex = xlNone
                            cntoperations = cntoperations - 1
                        End If
                        If .Range("AB" & rwend + 3).Interior.Color = ccgreen Then 'PATROL
                            .Range("AB" & rwend + 3).Interior.ColorIndex = xlNone
                            cntoperations = cntoperations - 1
                        End If
                        
                    ElseIf segtar.Address = .Range("R" & rwend + 7) Then 'spot blow
                        If .Range("R" & rwend + 3).Interior.Color = ccgreen Then 'full plow
                            .Range("R" & rwend + 3).Interior.ColorIndex = xlNone
                            cntoperations = cntoperations - 1
                        End If
                        If .Range("R" & rwend + 4).Interior.Color = ccgreen Then 'spot plow
                            .Range("R" & rwend + 4).Interior.ColorIndex = xlNone
                            cntoperations = cntoperations - 1
                        End If
                        If .Range("R" & rwend + 5).Interior.Color = ccgreen Then 'widen plow
                            .Range("R" & rwend + 5).Interior.ColorIndex = xlNone
                            cntoperations = cntoperations - 1
                        End If
                        If .Range("R" & rwend + 6).Interior.Color = ccgreen Then 'full blow
                            .Range("R" & rwend + 6).Interior.ColorIndex = xlNone
                            cntoperations = cntoperations - 1
                        End If
                        If .Range("AB" & rwend + 3).Interior.Color = ccgreen Then 'PATROL
                            .Range("AB" & rwend + 3).Interior.ColorIndex = xlNone
                            cntoperations = cntoperations - 1
                        End If
                        
                    ElseIf segtar.Address = .Range("R" & rwend + 8) Then 'widen blower
                        If .Range("R" & rwend + 3).Interior.Color = ccgreen Then 'full plow
                            .Range("R" & rwend + 3).Interior.ColorIndex = xlNone
                            cntoperations = cntoperations - 1
                        End If
                        If .Range("R" & rwend + 4).Interior.Color = ccgreen Then 'spot plow
                            .Range("R" & rwend + 4).Interior.ColorIndex = xlNone
                            cntoperations = cntoperations - 1
                        End If
                        If .Range("R" & rwend + 5).Interior.Color = ccgreen Then 'widen plow
                            .Range("R" & rwend + 5).Interior.ColorIndex = xlNone
                            cntoperations = cntoperations - 1
                        End If
                        If .Range("AB" & rwend + 3).Interior.Color = ccgreen Then 'PATROL
                            .Range("AB" & rwend + 3).Interior.ColorIndex = xlNone
                            cntoperations = cntoperations - 1
                        End If
                    End If
                    opcode optn
                    sequence2
                    RemoveCellSelectionBox
                
                'selected to unselected state
                Else
                    Target.Interior.ColorIndex = xlNone
                    optn = segtar.Offset(, 1)
                    cntoperations = cntoperations - 1
                    opcode optn
                    sequence10
                    RemoveCellSelectionBox
                End If
                MsgBox "Surface Conditions: " & cntconditions & Chr(13) & "Operations: " & cntoperations
                If cntconditions > 0 And cntoperations > 0 Then
                    .Shapes("btn_sendhome").Visible = True
                Else
                    .Shapes("btn_sendhome").Visible = False
                End If
                .Protect
            End If
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
You're comparing the address of the segtar cell to the value of another, which I don't think is what you intended?
 
Upvote 0
Solution
I am unable to get the code to recognize the IF criteria of the blue code ...
If the segtar address = .Range("R" & rwend + 4) .... R31 = .range then proceed with that code...
R31 = .range("R31")

This is true, but it skips right over that IF as if it were false.

Thoughts?

To expand on @RoryA's answer, you may think it is true, but it is probably not actually true.
Add some debug variables, then put them in the watch window to inspect while debugging.

VBA Code:
                    Dim A, B
                    A = segtar.Address
                    B = .Range("R" & rwend + 4)
                    ElseIf segtar.Address = .Range("R" & rwend + 4) Then 'spot plow
 
Upvote 0
Ahh hahh ...
Rich (BB code):
ElseIf segtar.Address = .Range("R" & rwend + 4).Address Then

Thanks for the nudge folks!
 
Upvote 0

Forum statistics

Threads
1,214,598
Messages
6,120,441
Members
448,966
Latest member
DannyC96

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