You can use them but it will only work if those are the exact colours that you have formatted the font in column A with.I am currently using red as vbred, so for blue and green, can we use vbgreen for green and vgblue for blue
Sub CompareAndHighlight()
Dim rng1 As Range, rng2 As Range, i As Long, j As Long
For i = 1 To Sheets("Input Data").Range("B" & Rows.Count).End(xlUp).Row
Set rng1 = Sheets("Input Data").Range("B" & i)
For j = 1 To Sheets("Priority Apt Code").Range("C" & Rows.Count).End(xlUp).Row
Set rng2 = Sheets("Priority Apt Code").Range("C" & j)
If StrComp(Trim(rng1.Text), Trim(rng2.Text), vbTextCompare) = 0 Then
rng1.Font.Color = vbRed
End If
Set rng2 = Nothing
Next j
Set rng1 = Nothing
Next i
End Sub
I'm afraid not as there appears to be no information about how to determine what gets coloured red, what blue and what green.Can you help me out in adding the highlight of green and blue in this code itself ..
That could be achieved with something like this... exporting those to respective sheets if we create sheet name "Red" for red, "Blue" to blue and "Green" to green.
Sub MoveColours()
Dim ColourMapping As Variant
Dim i As Long
ColourMapping = Array(vbRed, "Sheet2", vbBlue, "Sheet3", vbGreen, "Sheet4")
For i = LBound(ColourMapping) To UBound(ColourMapping) Step 2
With Sheets("Sheet1").UsedRange
.AutoFilter Field:=1, Criteria1:=ColourMapping(i), Operator:=xlFilterFontColor
.Copy Destination:=Sheets(ColourMapping(i + 1)).Range("A1")
.AutoFilter
End With
Next i
End Sub
Perhaps you have, but you haven't shown it or described it to us. Too hard to try to work out what you have, where and what it means by reading code.I have a sheet where the to be highlighted list is present.
Simplest way to answer that would be to try it.With the above code, can i just run the macro and it will change the font color in red, blue green and export it to assigned sheets?
Book1 | |||||
---|---|---|---|---|---|
A | B | C | |||
1 | Red | Green | Blue | ||
2 | Apt name | Apt name | Apt name | ||
3 | ACH10P01 | data 3 | data 4 | ||
4 | data 1 | data 5 | |||
5 | data 2 | ||||
6 | data 6 | ||||
7 | data 7 | ||||
8 | data 8 | ||||
9 | |||||
Sheet2 |
Sub ColourAndMove()
Dim ws2 As Worksheet
Dim i As Long, OrigCol As Long
Dim aColors As Variant
Dim rCrit As Range
aColors = Array(vbRed, vbGreen, vbBlue)
Set ws2 = Sheets("Sheet2")
With Sheets("Sheet1")
OrigCol = .Range("A1").Font.Color
For i = 1 To 3
Set rCrit = ws2.Range(ws2.Cells(2, i), ws2.Cells(ws2.Rows.Count, i).End(xlUp))
With .Range("A1", .Range("A" & .Rows.Count).End(xlUp)).Resize(, 4)
.AdvancedFilter Action:=xlFilterInPlace, CriteriaRange:=rCrit, Unique:=False
.Columns(1).SpecialCells(xlVisible).Font.Color = aColors(LBound(aColors) + i - 1)
.Range("A1").Font.Color = OrigCol
.Copy Destination:=Sheets(ws2.Cells(1, i).Value).Range("A1")
End With
If .FilterMode Then .ShowAllData
Next i
End With
End Sub
Book1 | ||||||
---|---|---|---|---|---|---|
A | B | C | D | |||
1 | Apt name | Calls | start time | end time | ||
2 | ACH10P01 | 2 | 8/15/2018 11:51:49 AM | 8/15/2018 12:23:53 PM | ||
3 | ALD10P01 | 8 | 8/15/18 12:36 PM | 8/15/18 9:27 PM | ||
4 | data 1 | 2 | Start time 3 | End time 3 | ||
5 | data 2 | 6 | Start time 4 | End time 4 | ||
6 | data 3 | 5 | Start time 5 | End time 5 | ||
7 | data 4 | 3 | Start time 6 | End time 6 | ||
8 | data 5 | 2 | Start time 7 | End time 7 | ||
9 | data 6 | 3 | Start time 8 | End time 8 | ||
10 | data 7 | 1 | Start time 9 | End time 9 | ||
11 | data 8 | 2 | Start time 10 | End time 10 | ||
12 | ||||||
Sheet1 |
1. Which line in the code is giving that error.Getting an error " Run-Time error '1004', This can't be applied to the selected range. Select a single cell in a range and try again"