Hi All,
I am really new to VBA coding. I have large spreadsheets that contain thousands of cells that have been coloured, but not via conditional formatting.
I need to autofill these cells dependent on the RGB code, with specific text, back into the cell that is coloured. I have tried two Macros so far that I found online, one I couldn't make work as I didn't and still do not understand how to write a Sub to support the Function. The other works, but it lists the wording into the column beside the cell that coloured. (Both below)
Function VBA code:
Function CheckColor1(r as Range)
If r.Interior.Color = RGB(255, 192, 0) Then
CheckColor1 = "Orange"
ElseIf r.Interior.Color = RGB(0, 176, 240) Then
CheckColor1 = "Blue"
ElseIf r.Interior.Color = RGB(255, 255, 0) Then
CheckColor1 = "Yellow"
Else
CheckColor1 = " "
End If
End Function
Sub Macro aligned to the side:
Sub What_Color()
Application.ScreenUpdating = False
Dim i As Integer
Dim Lastrow As Long
Lastrow = Cells(Rows.Count, "A").End(xlUp).Row
For i = 1 To Lastrow
If Cells(i, 1).Interior.Color = RGB(255, 255, 0) Then Cells(i, 2).Value = "Yellow"
If Cells(i, 1).Interior.Color = RGB(148, 138, 34) Then Cells(i, 2).Value = "Brown"
Next
Application.ScreenUpdating = True
End Sub
Below are two attempts that I have made after reviewing different posts and these , neither work unsurprisingly:
Attempt 1:
Sub CT()
Application.ScreenUpdating = False
Dim R As Range
Set R = ActiveSheet.Range("A1:G10")
If R.Interior.Color = RGB(255, 192, 0) Then Cells.Value = "Orange"
If R.Interior.Color = RGB(0, 176, 240) Then Cells.Value = "Blue"
If R.Interior.Color = RGB(255, 255, 0) Then Cells.Value = "Yellow"
Application.ScreenUpdating = True
End Sub
Attempt 2:
Sub Colour ()
Application.ScreenUpdating = False
Dim i As Integer
Dim x as Range
Set x = Worksheets("Sheet name").Cells
Dim ws As Worksheet
Set ws = ActiveSheet
For i = 1 To Lastrow
If Cells(i, 1).Interior.Color = RGB(255, 192, 0) Then Cells(i, 1).Value = "Orange"
If Cells(i, 1).Interior.Color = RGB(0, 176, 240) Then Cells(i, 1).Value = "Blue"
If Cells(i, 1).Interior.Color = RGB(255, 255, 0) Then Cells(i, 1).Value = "Yellow"
Next
Application.ScreenUpdating = True
End Sub
Any help / advice would be sincerely appreciated
I am really new to VBA coding. I have large spreadsheets that contain thousands of cells that have been coloured, but not via conditional formatting.
I need to autofill these cells dependent on the RGB code, with specific text, back into the cell that is coloured. I have tried two Macros so far that I found online, one I couldn't make work as I didn't and still do not understand how to write a Sub to support the Function. The other works, but it lists the wording into the column beside the cell that coloured. (Both below)
Function VBA code:
Function CheckColor1(r as Range)
If r.Interior.Color = RGB(255, 192, 0) Then
CheckColor1 = "Orange"
ElseIf r.Interior.Color = RGB(0, 176, 240) Then
CheckColor1 = "Blue"
ElseIf r.Interior.Color = RGB(255, 255, 0) Then
CheckColor1 = "Yellow"
Else
CheckColor1 = " "
End If
End Function
Sub Macro aligned to the side:
Sub What_Color()
Application.ScreenUpdating = False
Dim i As Integer
Dim Lastrow As Long
Lastrow = Cells(Rows.Count, "A").End(xlUp).Row
For i = 1 To Lastrow
If Cells(i, 1).Interior.Color = RGB(255, 255, 0) Then Cells(i, 2).Value = "Yellow"
If Cells(i, 1).Interior.Color = RGB(148, 138, 34) Then Cells(i, 2).Value = "Brown"
Next
Application.ScreenUpdating = True
End Sub
Below are two attempts that I have made after reviewing different posts and these , neither work unsurprisingly:
Attempt 1:
Sub CT()
Application.ScreenUpdating = False
Dim R As Range
Set R = ActiveSheet.Range("A1:G10")
If R.Interior.Color = RGB(255, 192, 0) Then Cells.Value = "Orange"
If R.Interior.Color = RGB(0, 176, 240) Then Cells.Value = "Blue"
If R.Interior.Color = RGB(255, 255, 0) Then Cells.Value = "Yellow"
Application.ScreenUpdating = True
End Sub
Attempt 2:
Sub Colour ()
Application.ScreenUpdating = False
Dim i As Integer
Dim x as Range
Set x = Worksheets("Sheet name").Cells
Dim ws As Worksheet
Set ws = ActiveSheet
For i = 1 To Lastrow
If Cells(i, 1).Interior.Color = RGB(255, 192, 0) Then Cells(i, 1).Value = "Orange"
If Cells(i, 1).Interior.Color = RGB(0, 176, 240) Then Cells(i, 1).Value = "Blue"
If Cells(i, 1).Interior.Color = RGB(255, 255, 0) Then Cells(i, 1).Value = "Yellow"
Next
Application.ScreenUpdating = True
End Sub
Any help / advice would be sincerely appreciated