Color the Changed Line from A to AL with solid interior color 34

Nlhicks

Active Member
Joined
Jan 8, 2021
Messages
264
Office Version
  1. 365
Platform
  1. Windows
This code will change the values and color them Red, however it is not applying the Light blue highlight to the entire line. Any suggestions?

VBA Code:
   With wksWorkOn
            lngLastRow = .Range("A2", .Range("A" & Rows.Count).End(xlUp)).SpecialCells(xlCellTypeVisible).Cells(1).Row
             wksFrom.Range("J13").Value = .Range("A2:A685").SpecialCells(xlCellTypeVisible).Cells.Value
                 For lngLooper = 11 To 18
                    With .Cells(lngLastRow, lngLooper - 9)
                        If wksFrom.Cells(lngLooper, "C") <> wksFrom.Cells(lngLooper, "F") And wksFrom.Cells(lngLooper, "F") <> "" Then
                            .Font.Color = vbRed
                        'If binColour Then
                        With .Range("A" & lngLastRow & ":AL" & lngLastRow).Interior
                            .Pattern = xlSolid
                            .PatternColorIndex = xlAutomatic
                            .ColorIndex = 34
                            .TintAndShade = 0
                            .PatternTintAndShade = 0
                        End With
                    .Value = wksFrom.Cells(lngLooper, "F").Value
                    Else
                        If wksFrom.Cells(lngLooper, "F") = "" Then
                            .Value = .Value
                        End If
                        End If
                    'End If
                    End With
                Next lngLooper
        End With
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
Nothing obvious to me. Did you step through your code and make sure that part was being executed?
Indentation is not right, so maybe I missed something.
 
Upvote 0
Correction (I think but am not sure, still fixing indentation) - your With block is inside of an If block that is commented out (disabled).
 
Upvote 0
This is all that I am getting. The If blnColour Then was commented out by HaHo.
Great Plains+Great Plains 13.8kV
95
CT (WAPA)
95
CT (WAPA)
95
CT (WAPA)
95
CT( WAPA)Great PlainsGreat Plains
 
Upvote 0
So the math is working and the updates are getting updated but the line is remaining colorless
 
Upvote 0
It doesn't look right to me. The disabled If then has an Else part which is not disabled thus it becomes part of the first If which probably is not good. I can't test it, so still suggest you step through it and watch what is happening. Maybe this will help you follow what I'm saying. Notes are within.
VBA Code:
  With wksWorkOn
      lngLastRow = .Range("A2", .Range("A" & Rows.Count).End(xlUp)).SpecialCells(xlCellTypeVisible).Cells(1).Row
      wksFrom.Range("J13").Value = .Range("A2:A685").SpecialCells(xlCellTypeVisible).Cells.Value
      For lngLooper = 11 To 18
         With .Cells(lngLastRow, lngLooper - 9)
            If wksFrom.Cells(lngLooper, "C") <> wksFrom.Cells(lngLooper, "F") And wksFrom.Cells(lngLooper, "F") <> "" Then
               .Font.Color = vbRed
               'If binColour Then
                  With .Range("A" & lngLastRow & ":AL" & lngLastRow).Interior
                     .Pattern = xlSolid
                     .PatternColorIndex = xlAutomatic
                     .ColorIndex = 34
                     .TintAndShade = 0
                     .PatternTintAndShade = 0
                  End With
                  .Value = wksFrom.Cells(lngLooper, "F").Value
               Else '<<this was written for the second If (?) but becomes part of the first If so is misaligned here in that case
                  If wksFrom.Cells(lngLooper, "F") = "" Then
                     .Value = .Value
                  End If
               End If 'this would terminate the first If but is misaligned too
            'End If
         End With
      Next lngLooper
   End With
 
Upvote 1
Solution
Here's another thought: with respect to .Range where you are trying to colour the row
With .Range("A" & lngLastRow & ":AL" & lngLastRow).Interior

what is its parent??
is it .Cells(lngLastRow, lngLooper - 9) because of the previous With .Cells(lngLastRow, lngLooper - 9)

If so then you're saying
wksWorkOn.Cells(lngLastRow, lngLooper - 9).Range("A" & lngLastRow & ":AL" & lngLastRow).Interior

which implies that a Cell object contains a Range object. I'm new to Excel vba (not Access) so I don't know if that's possible. Would have to check.
 
Upvote 0

Forum statistics

Threads
1,223,997
Messages
6,175,871
Members
452,679
Latest member
darryl47nopra

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