Hi,
I am trying to reference a range in a table, to apply conditional formatting through VBA, but unfortunately it is not working. I am getting my column names of the table by running the FOR EACH loop, and saving the results in 'FormulaNum' string variable. I'm trying to use this variable as a RANGE , when i set my range (rRangeToFormat), but it doesn't work. If i hard code the column names of my table, while setting the range, it does work. Below is my code. Thank you for providing help on this.
I am trying to reference a range in a table, to apply conditional formatting through VBA, but unfortunately it is not working. I am getting my column names of the table by running the FOR EACH loop, and saving the results in 'FormulaNum' string variable. I'm trying to use this variable as a RANGE , when i set my range (rRangeToFormat), but it doesn't work. If i hard code the column names of my table, while setting the range, it does work. Below is my code. Thank you for providing help on this.
Code:
Dim RngFormula As Range
Dim wsFormula As Worksheet
Dim FormulaNum As String
Set wsFormula = Worksheets("VB")
For Each RngFormula In wsFormula.Range("TblSec")
If Not IsEmpty(RngFormula) Then
FormulaNum = FormulaNum & "tbl_1[" & RngFormula & "],"
End If
Next RngFormula
FormulaNum = Left(FormulaNum, Len(FormulaNum) - 1)
'MsgBox FormulaNum
Set rRangeToFormat = Worksheets("Vocab").Range(FormulaNum)
With rRangeToFormat
.FormatConditions.Delete
.FormatConditions.AddColorScale ColorScaleType:=3