Hi everyone,
I am new here and in need of your expertise. I recently watched https://youtu.be/u8F7U7W6ka4 where Bill instructs how to create a VBA to colour code unique number values within excel....perfect! The problem I am now having is that when I receive an excel worksheet it is already pre-populated with data and I want to run the VBA through the data that is there. I had thought I could just open the excel and then paste the VBA however, that does not work. I also tried copying the data from one book, creating a second book with the VBA present and then pasting the data in and it did work up to 28 lines only. The rest of the data did not follow the VBA rules. Here is the VBA I am using
Private Sub Worksheet_Change(ByVal Target As Range)
Set WF = Application.WorksheetFunction
If Target.Cells.Count = 1 Then
If Target.Column = 1 Then
x = 0
On Error Resume Next
x = WF.Match(Target.Value, _
Range("A1").Resize(Target.Row - 1), _
0)
On Error GoTo 0
If x > 0 Then
' duplicate value... copy the old color
Target.Interior.Color = Cells(x, 1).Interior.Color
Else
' Choose a new color
Target.Interior.Color = RGB( _
WF.RandBetween(0, 256), _
WF.RandBetween(0, 256), _
WF.RandBetween(0, 256))
End If
End If
End If
End Sub
If someone could help me figure out how to run the VBA over top of data that is already populated that would be great....in addition how to get it to work for more than 28 lines. As a side note - if I started to manually type different numbers the VBA was working but, as I said, for some reason the VBA is simply not running beyond 28 lines when large data sets are already present.
Thank you all!
I am new here and in need of your expertise. I recently watched https://youtu.be/u8F7U7W6ka4 where Bill instructs how to create a VBA to colour code unique number values within excel....perfect! The problem I am now having is that when I receive an excel worksheet it is already pre-populated with data and I want to run the VBA through the data that is there. I had thought I could just open the excel and then paste the VBA however, that does not work. I also tried copying the data from one book, creating a second book with the VBA present and then pasting the data in and it did work up to 28 lines only. The rest of the data did not follow the VBA rules. Here is the VBA I am using
Private Sub Worksheet_Change(ByVal Target As Range)
Set WF = Application.WorksheetFunction
If Target.Cells.Count = 1 Then
If Target.Column = 1 Then
x = 0
On Error Resume Next
x = WF.Match(Target.Value, _
Range("A1").Resize(Target.Row - 1), _
0)
On Error GoTo 0
If x > 0 Then
' duplicate value... copy the old color
Target.Interior.Color = Cells(x, 1).Interior.Color
Else
' Choose a new color
Target.Interior.Color = RGB( _
WF.RandBetween(0, 256), _
WF.RandBetween(0, 256), _
WF.RandBetween(0, 256))
End If
End If
End If
End Sub
If someone could help me figure out how to run the VBA over top of data that is already populated that would be great....in addition how to get it to work for more than 28 lines. As a side note - if I started to manually type different numbers the VBA was working but, as I said, for some reason the VBA is simply not running beyond 28 lines when large data sets are already present.
Thank you all!