Good Day,
I am having trouble with an excel formula. I would like for my VBA script to delete all rows where a specified word exists in a specified column. My problem, however, is that the columns can sometimes change so I would like the script to be based on the headers rather than the column letter.
Here's what I have so far:
---------------
Dim Firstrow As Long
Dim LastRow As Long
Dim Lrow As Long
Dim CalcMode As Long
Dim ViewMode As Long
With Application
CalcMode = .Calculation
.Calculation = xlCalculationManual
.ScreenUpdating = False
End With
With ActiveSheet
.Select
ViewMode = ActiveWindow.View
ActiveWindow.View = xlNormalView
.DisplayPageBreaks = False
Firstrow = 2
LastRow = .UsedRange.Rows(.UsedRange.Rows.Count).Row
For Lrow = LastRow To Firstrow Step -1
With .Cells(Lrow, "H")
If Not IsError(.Value) Then
If Not .Value = "SampleValue1" Then .EntireRow.Delete
End If
End With
Next Lrow
End With
ActiveWindow.View = ViewMode
With Application
.ScreenUpdating = True
.Calculation = CalcMode
End With
---------------
I am having trouble with an excel formula. I would like for my VBA script to delete all rows where a specified word exists in a specified column. My problem, however, is that the columns can sometimes change so I would like the script to be based on the headers rather than the column letter.
Here's what I have so far:
---------------
Dim Firstrow As Long
Dim LastRow As Long
Dim Lrow As Long
Dim CalcMode As Long
Dim ViewMode As Long
With Application
CalcMode = .Calculation
.Calculation = xlCalculationManual
.ScreenUpdating = False
End With
With ActiveSheet
.Select
ViewMode = ActiveWindow.View
ActiveWindow.View = xlNormalView
.DisplayPageBreaks = False
Firstrow = 2
LastRow = .UsedRange.Rows(.UsedRange.Rows.Count).Row
For Lrow = LastRow To Firstrow Step -1
With .Cells(Lrow, "H")
If Not IsError(.Value) Then
If Not .Value = "SampleValue1" Then .EntireRow.Delete
End If
End With
Next Lrow
End With
ActiveWindow.View = ViewMode
With Application
.ScreenUpdating = True
.Calculation = CalcMode
End With
---------------