I have been using this code as a macro to quickly highlight all items within a range under a certain value. i have just cut and pasted the code across several sheets and just changed the range of cells where it looks.
cut and paste and change the range. over and over and over again.
now im getting a runtime error 91bject variable or with block not set. i;m by no means good at VBA this is just a small project im working on at school and i cant debug this. any help would be appreciated.
heres my code that works on all the other worksheets
cut and paste and change the range. over and over and over again.
now im getting a runtime error 91bject variable or with block not set. i;m by no means good at VBA this is just a small project im working on at school and i cant debug this. any help would be appreciated.
heres my code that works on all the other worksheets
Code:
Sub Insert_Inventory()
Dim cell As Range
Dim NewRange As Range
Dim MyCount As Long
MyCount = 1
For Each cell In Range("E8:E13") ' These values indicate the range in the "F" column that the product numbers run from
If cell.Value <> "" Then 'If you add or take away a row in the range simply change the numbers in the range ie. "F5:F14"
If cell.Value <= 5 Then
If MyCount = 1 Then Set NewRange = cell
Set NewRange = Application.Union(NewRange, cell)
MyCount = MyCount + 1
End If
End If
Next cell
NewRange.Interior.ColorIndex = 3 ' <--- this number dictates the colour the cell will turn if it needs to be reordered
For Each cell In Range("E22:E26")
If cell.Value <> "" Then
If cell.Value <= 15 Then
If MyCount = 1 Then Set NewRange = cell
Set NewRange = Application.Union(NewRange, cell)
MyCount = MyCount + 1
End If
End If
Next cell
NewRange.Interior.ColorIndex = 3
For Each cell In Range("G36:G42")
If cell.Value <> "" Then
If cell.Value <= 5 Then
If MyCount = 1 Then Set NewRange = cell
Set NewRange = Application.Union(NewRange, cell)
MyCount = MyCount + 1
End If
End If
Next cell
NewRange.Interior.ColorIndex = 3
For Each cell In Range("G48:G65")
If cell.Value <> "" Then
If cell.Value <= 5 Then
If MyCount = 1 Then Set NewRange = cell
Set NewRange = Application.Union(NewRange, cell)
MyCount = MyCount + 1
End If
End If
Next cell
NewRange.Interior.ColorIndex = 3
End Sub