HighLight cells range

Vincent88

Active Member
Joined
Mar 5, 2021
Messages
382
Office Version
  1. 2019
Platform
  1. Windows
  2. Mobile
Hi All,
I need help in the following code.
In Worksheet "Data", each cell value in Column AC represents the column number and that of Column AD represents the row number in another worksheet.
I need to loop thru column AC if the difference of the two values is over 5 and the value of the two cells in next column AD is the same, then trigger to format the cells in another worksheet.

VBA Code:
Sub highlightCells35()
Dim ws As Worksheet
Dim wsm As Worksheet
Set ws = Worksheets("Data")
Set wsm = ActiveSheet

Dim lastrow As Long
 lastrow = ws.Range("AA1").End(xlDown).Row
 Debug.Print lastrow
Dim iCol As Range
Dim rngData As Range
    Set rngData = ws.Range("AA1:AA" & lastrow)
Application.ScreenUpdating = False
Application.EnableEvents = False

With rngData
    For Each iCol In rngData.Columns(3)  'in Column AC
        If (iCol.Offset(1).Value - iCol.Value) - 1 > 5 And iCol.Offset(, 1).Value = iCol.Offset(1, 1).Value Then
                
                  Dim areaH As Range
                  areaH = wsm.Range(Cells(iCol.Offset(, 1), iCol), Cells(iCol.Offset(1, 1), iCol.Offset(1)))
                  With areaH
                      .Font.Underline = xlUnderlineStyleSingle
                  End With
              Else
                  With areaH
                     .Font.Underline = xlNone
                  End With
        End If
    
    Next iCol
End With

Application.ScreenUpdating = True
Application.EnableEvents = True


End Sub

AgentProposal_Roster0728_1025M.xlsm
AAABACAD
1D3D43
2F3F63
3I3I93
4J3J103
5W3W233
6X3X243
7AD3AD303
8AE3AE313
9AK3AK373
10AL3AL383
11H4H84
12I4I94
13J4J104
14M4M134
15W4W234
16X4X244
17AD4AD304
18AE4AE314
19AK4AK374
20AL4AL384
21J5J105
22L5L125
23W5W235
24X5X245
25AD5AD305
26AE5AE315
27AK5AK375
28AL5AL385
29C6C36
30H6H86
31I6I96
32J6J106
33Q6Q176
34W6W236
35X6X246
36AD6AD306
37AE6AE316
38AK6AK376
39AL6AL386
Data
 

Attachments

  • highlight code error.png
    highlight code error.png
    20.3 KB · Views: 3

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
Try
VBA Code:
    For Each iCol In rngData.Columns(3).Cells  'in Column AC
 
Upvote 0
Solution
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,215,503
Messages
6,125,179
Members
449,212
Latest member
kenmaldonado

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