Hi Experts,
I have a problem with coloring matching values through VBA.
I have posted this on a different forum, but I really need a solution for my issue.
Link to the cross-post: Ozgrid
I have a sheet called "Filtered Vacations", that retrieves filtered data from a different workbook. This work good.
In cell B4 to O4 I have dates, and under those dates are the filtered values from the other workbook.
The list of values under those dates are not fixed and change depending on the values that have been retrieved.
So each date has a separate set of values.
I also have 7 sheets that represent the days of the week ("Mon,"Tue", "Wed",...)
In those sheets on cell I3 I have a date.
The date on "Mon" is in the format "mm/dd/yyyy" the rest of the sheets are a link to the "Mon"sheet by adding +1 to the date.
The actual range of the columns that I want to use in my code is Range("C9:C65,E9:E65,G9:G59,I9:I65,K9:K65,M9:M65,O9:O65,C77:C133,E77:E133,G77:G127,I77:I133,K77:K133,M77:M133,O77:O133,C145:C201,E145:E201,G145:G195,I145:I201,K145:K201,M145:M201,O145:O201")
I would like to have a vba code that does the following:
It needs to take the date from cell I3 in the 7-sheets and check / compare that with the dates in "Filtered Vacations". Range (B4:O4)
If a match is found then the values in "Filtered Vacations" that are below the cell with that date needs to be checked in that sheet where the date was found. (one of the 7-sheets). When a match is found that cell needs to be colored light grey in one of the 7-sheets.
For example: If a date is found on cell G4 that matches the date in sheet "Wed" than the values from the column G need to be compared with the values in the columns/range in sheet "Wed".
When a match is found that cell needs to be colored light grey.
The values in sheet "Filtered Vacations" are numbers (xxx). The values in the 7 sheets that represent the days of the week are a combination of numbers & letters (" xxx x.xxxxxx). The match should be only on the 3 numbers ( the combination always starts with 3 numbers and then letters)
I am trying to adjust the following VBA code, but I have no luck with that.
This code works partially, because it colors ALL the values that are found in the sheet "Filtered Vacations" and it does not just look at the date and the values below that date.
I hope someone can help me with my issue, any help is appreciated.
I have a problem with coloring matching values through VBA.
I have posted this on a different forum, but I really need a solution for my issue.
Link to the cross-post: Ozgrid
I have a sheet called "Filtered Vacations", that retrieves filtered data from a different workbook. This work good.
In cell B4 to O4 I have dates, and under those dates are the filtered values from the other workbook.
The list of values under those dates are not fixed and change depending on the values that have been retrieved.
So each date has a separate set of values.
I also have 7 sheets that represent the days of the week ("Mon,"Tue", "Wed",...)
In those sheets on cell I3 I have a date.
The date on "Mon" is in the format "mm/dd/yyyy" the rest of the sheets are a link to the "Mon"sheet by adding +1 to the date.
The actual range of the columns that I want to use in my code is Range("C9:C65,E9:E65,G9:G59,I9:I65,K9:K65,M9:M65,O9:O65,C77:C133,E77:E133,G77:G127,I77:I133,K77:K133,M77:M133,O77:O133,C145:C201,E145:E201,G145:G195,I145:I201,K145:K201,M145:M201,O145:O201")
I would like to have a vba code that does the following:
It needs to take the date from cell I3 in the 7-sheets and check / compare that with the dates in "Filtered Vacations". Range (B4:O4)
If a match is found then the values in "Filtered Vacations" that are below the cell with that date needs to be checked in that sheet where the date was found. (one of the 7-sheets). When a match is found that cell needs to be colored light grey in one of the 7-sheets.
For example: If a date is found on cell G4 that matches the date in sheet "Wed" than the values from the column G need to be compared with the values in the columns/range in sheet "Wed".
When a match is found that cell needs to be colored light grey.
The values in sheet "Filtered Vacations" are numbers (xxx). The values in the 7 sheets that represent the days of the week are a combination of numbers & letters (" xxx x.xxxxxx). The match should be only on the 3 numbers ( the combination always starts with 3 numbers and then letters)
I am trying to adjust the following VBA code, but I have no luck with that.
This code works partially, because it colors ALL the values that are found in the sheet "Filtered Vacations" and it does not just look at the date and the values below that date.
I hope someone can help me with my issue, any help is appreciated.
VBA Code:
Sub ColorMatchingCells()
Dim wsMon As Worksheet
Dim wsFilteredVacations As Worksheet
Dim cellMon As Range
Dim cellFilteredVacations As Range
Dim targetRanges() As Variant
Dim targetRange As Range
Dim i As Integer
Dim filteredValue As String
Dim monValue As String
Set wsMon = ThisWorkbook.Sheets("Mon")
Set wsFilteredVacations = ThisWorkbook.Sheets("Filtered Vacations")
targetRanges = Array( _
wsMon.Range("C9:C65,E9:E65,G9:G59,I9:I65,K9:K65,M9:M65,O9:O65"), _
wsMon.Range("C77:C133,E77:E133,G77:G127,I77:I133,K77:K133,M77:M133,O77:O133"), _
wsMon.Range("C145:C201,E145:E201,G145:G195,I145:I201,K145:K201,M145:M201,O145:O201"))
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
For i = LBound(targetRanges) To UBound(targetRanges)
Set targetRange = targetRanges(i)
For Each cellFilteredVacations In wsFilteredVacations.Range("B5:O40")
If Not IsEmpty(cellFilteredVacations) Then
filteredValue = Left(cellFilteredVacations.Value, 3)
For Each cellMon In targetRange
If Not IsEmpty(cellMon) Then
monValue = Left(cellMon.Value, 3)
If monValue = filteredValue Then
cellMon.Interior.Color = RGB(192, 192, 192) ' Light grey color
End If
End If
Next cellMon
End If
Next cellFilteredVacations
Next i
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
End Sub