I have a perplexing question. It’s not a problem because I can work with the results, its just understanding why it will not work with a modification in code that should return the same results but doesn’t.
This is my base code…..
I have one code that works well…..
This code works well in that it gives the actual cell color based on values in F, G, H. Such as this screenshot shows…..
But if I change my code to the LDR_E format it doesn’t work even though I believe it’s the same results….
Why will this not work, all I get is blank column E?
This is my base code…..
VBA Code:
Dim WS As Worksheet
Set WS = ShGE03
With WS
Dim SDR_E As Long: SDR_E = 5 'StartDataRow_(column)E = ColorName
Dim LDR_E As Long: LDR_E = .Cells(Rows.Count, "E").End(xlUp).Row ' LastDataRow_(column)E = ColorName 'do not offset for blanks, will affect some code for (missing & duplicates)
Dim Rowdata As Long '''For Rowdata = SDR_E To LDR_E 'for reference
Dim TextChange As Long
TextChange = .Range("V5").Value
End With
I have one code that works well…..
VBA Code:
With WS
Call TurnOffStuff 'Turns off background Excel Functions that might interfere with calculations
For Rowdata = SDR_E To LDR_E
Dim RANGE_E As Range
Set RANGE_E = .Range("E" & Rowdata)
Dim RANGE_F As Range
Set RANGE_F = .Range("F" & Rowdata)
Dim RANGE_G As Range
Set RANGE_G = .Range("G" & Rowdata)
Dim RANGE_H As Range
Set RANGE_H = .Range("H" & Rowdata)
Dim RANGE_M As Range
Set RANGE_M = .Range("M" & Rowdata)
RANGE_E.Interior.Color = RGB(RANGE_F.Value, RANGE_G.Value, RANGE_H.Value)
If RANGE_M.Value >= TextChange Then
RANGE_E.Font.Color = RGB(0, 0, 0) 'black
Else
RANGE_E.Font.Color = RGB(255, 255, 255) 'white
End If
Next
Call TurnOnStuff 'Turns on background Excel Functions that might interfere with calculations
End With
This code works well in that it gives the actual cell color based on values in F, G, H. Such as this screenshot shows…..
But if I change my code to the LDR_E format it doesn’t work even though I believe it’s the same results….
VBA Code:
With WS
Call TurnOffStuff 'Turns off background Excel Functions that might interfere with calculations
Dim RANGE_E As Range
Set RANGE_E = .Range("E5:E" & LDR_E)
Dim RANGE_F As Range
Set RANGE_F = .Range(“F5:F" & LDR_E)
Dim RANGE_G As Range
Set RANGE_G = .Range(“G5:G" & LDR_E)
Dim RANGE_H As Range
Set RANGE_H = .Range (“H5:H" & LDR_E)
Dim RANGE_M As Range
Set RANGE_M = .Range(“M5:M" & LDR_E)
RANGE_E.Interior.Color = RGB(RANGE_F.Value, RANGE_G.Value, RANGE_H.Value)
If RANGE_M.Value >= TextChange Then
RANGE_E.Font.Color = RGB(0, 0, 0) 'black
Else
RANGE_E.Font.Color = RGB(255, 255, 255) 'white
End If
Next
Call TurnOnStuff 'Turns on background Excel Functions that might interfere with calculations
End With
Why will this not work, all I get is blank column E?