Vincent88
Active Member
- Joined
- Mar 5, 2021
- Messages
- 382
- Office Version
- 2019
- Platform
- Windows
- Mobile
Hi Guys, I want the make change of the columns in a dynamic range from col H to AL.
In each column, find if these text - "E", "G" and "N" appears only one, if conditions meet, trigger the change of that column
I don't think I am using the correct dim and reference !
Please help.
In each column, find if these text - "E", "G" and "N" appears only one, if conditions meet, trigger the change of that column
I don't think I am using the correct dim and reference !
Please help.
VBA Code:
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
Select Case Sh.Name
Case "Data"
Exit Sub
Case Else
End Select
'Highlight Column in Range
If Not Intersect(Target, Range("H3:AL" & lastRow)) Is Nothing Then
If Not IsNumeric(Target.Value) Then
Dim gVal As String, eVal As Integer, nVal As Integer
Dim rng As Range, colrng As Range
Dim lastRow As Long
lastRow = Range("A3").End(xlDown).Row
Set rng = Range("H3", Range("AL" & Rows.Count).End(xlUp))
eVal = Application.WorksheetFunction.Range(Range(Columns.Count & Rows.Count).End(xlUp), "E") = 1
gVal = Application.WorksheetFunction.Range(Range(Columns.Count & Rows.Count).End(xlUp), "G") = 1
nVal = Application.WorksheetFunction.Range(Range(Columns.Count & Rows.Count).End(xlUp), "N") = 1
'eVal = Application.WorksheetFunction.CountIf(Range("H3:H14"), "E") = 1
'gVal = Application.WorksheetFunction.CountIf(Range("H3:H14"), "G") = 1
'nVal = Application.WorksheetFunction.CountIf(Range("H3:H14"), "N") = 1
If eVal = True And gVal = True And nVal = True Then Exit Sub
'No Change if criteria met
With rng.Borders
.LineStyle = xlContinuous
.Weight = xlThin
End With
If eVal = True And gVal = True Then
'Only these criteria met
cell(1, Columns.Count).Font.FontStyle = "Bold Italic"
Else
'Any combinations of eVal, gVal and nVal triggers the change
Set colrng = Range(Columns.Count & Rows.Count).End(xlUp)
With colrng.Borders
.LineStyle = xlContinuous
.Weight = xlThick
.Color = vbBlue
End With
End Sub