Fairly new to VBA here. I found some code online to delete rows with a particular word/value in column A. It works fine on my computer but won't work on a coworker's. Any idea why?
We're both on Excel 2003. I've tried taking out the portion of the code that adjusts the view and calc mode but the problem persists.
We're both on Excel 2003. I've tried taking out the portion of the code that adjusts the view and calc mode but the problem persists.
Code:
Dim stringToFind As String
Windows("Macro.xls").Activate
stringToFind = Range("A22")
'Cell A22 above is a particular word.
' Procedure below activates a 3rd file whose filename changes from month to month
For Each WkBook In Workbooks
If WkBook.Name <> "Query.xls" And WkBook.Name <> "Macro.xls" Then
WkBook.Activate
Exit For
End If
Next WkBook
'Code below deletes all rows with the stringToFind value
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
'We use the ActiveSheet
With ActiveSheet
'We select the sheet so we can change the window view
.Select
'If you are in Page Break Preview Or Page Layout view go
'back to normal view, we do this for speed
ViewMode = ActiveWindow.View
ActiveWindow.View = xlNormalView
'Turn off Page Breaks, we do this for speed
.DisplayPageBreaks = False
'Set the first and last row to loop through
Firstrow = .UsedRange.Cells(1).Row
Lastrow = .UsedRange.Rows(.UsedRange.Rows.Count).Row
'We loop from Lastrow to Firstrow (bottom to top)
For Lrow = Lastrow To Firstrow Step -1
'We check the values in the A column in this example
With .Cells(Lrow, "A")
If Not IsError(.Value) Then
If .Value = stringToFind Then .EntireRow.Delete
'This will delete each row with the Value stringToFind
'in Column A, case sensitive.
End If
End With
Next Lrow
End With
ActiveWindow.View = ViewMode
With Application
.ScreenUpdating = True
.Calculation = CalcMode
End With
Last edited: