Problem when reusing VBA code for highlighting cells between sheets

dirtybathtowel

New Member
Joined
Feb 9, 2023
Messages
1
Office Version
  1. 2016
Platform
  1. Windows
Hi all,

I have a workflow manager for customer service that lists cases row-by-row, including a column for the "next step" which tells me at all times what I need to do next for each particular case.
My problem is that I am trying to write a Sub called Highlight_Actionables() that highlights cells in the "next step" column when the row fulfills certain conditions.
Currently in one sheet of cases I have this formula:

VBA Code:
Sub ActionablesHighlighting()
    Application.ScreenUpdating = False
    'Grabbing the "next step" column
    Dim MyRange as Range
    Set MyRange = Range("D3:D100")
    
    Range("D3").Select
    For i = 1 to MyRange.Count
        Dim PONumCell as Range
        Set PONumCell = ActiveCell.Offset(0,4)
        If ActiveCell.Value = "Update PO number" And_
        PONumCell.Value = "released" Or PO NumCell.Value = "Released" Then
            ActiveCell.Interior.Color = vbYellow
        End If
        ActiveCell.Offset(1,0).Select
    Next i
    Range("D3").Select
    Application.ScreenUpdating = True
End Sub

This works perfectly, but when I paste it over into another sheet, it doesn't work. I've adjusted the range from D to F because that's where the step column now is, and changed the offset from 4 to 5 because there's an additional row inbetween the steps column and PONum column now. Everything works as it should, and I can see that the code iterates through every line even on the new sheet, returning appropriate values in MsgBox for ActiveCell.Value and PONumCell.Value. Yet, for some reason, it just refuses to highlight the steps (D) cell now. I've tried everything and it won't highlight, just on my sheet. I'm sure all the references are correct. Any help is appreciated.
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
To test I reduced range to 10 and added Msgbox's to state where its looking. They will need removing once it works and the range back to 100

VBA Code:
Sub ActionablesHighlighting()
    Application.ScreenUpdating = False
    'Grabbing the "next step" column
    Dim MyRange As Range
    Set MyRange = Range("D3:D10") 'reduced to check from 100
    
    Range("D3").Select
    For i = 1 To MyRange.Count
        Dim PONumCell As Range
        Set PONumCell = ActiveCell.Offset(0, 4)
        MsgBox "Row " & PONumCell.Row & " | Column " & PONumCell.Column
        If ActiveCell.Value = "Update PO number" And _
            PONumCell.Value = "released" Or PONumCell.Value = "Released" Then
            ActiveCell.Interior.Color = vbYellow
        End If
        ActiveCell.Offset(1, 0).Select
        MsgBox "Row " & ActiveCell.Row & " | Column " & ActiveCell.Column
    Next i
    Range("D3").Select
    Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,594
Messages
6,120,436
Members
448,964
Latest member
Danni317

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