Help with macro

Mldeuser

Well-known Member
Joined
Dec 27, 2008
Messages
563
Office Version
  1. 365
Platform
  1. Windows
I need some help with the macro below, I would like to have it run for sheet 1 only and I would like to be able to run it from wny sheet in the workbook

Thank you

mark





Sub DeleteRows()
Dim iRow As Long

With ActiveSheet
For iRow = .Cells(.Rows.Count, "B").End(xlUp).Row To 5 Step -1
If .Cells(iRow, "B").Value = "Mark" And _
InStr(1, .Cells(iRow, "C").Value, "Grant", vbTextCompare) And _
InStr(1, .Cells(iRow, "E").Value, "Repower", vbTextCompare) Then
.Rows(iRow).Delete
End If
Next iRow
End With
End Sub
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
Hi Mark,

When you say 'sheet 1' do you mean the name of the sheet is 'sheet 1' or you want the code to always run on the first tab (i.e furthest left tab) in the workbook as there's a big difference.

Robert
 
Upvote 0
I am refering the excel naming of the worksheets, I renamed sheet1 but I want the macro to reference the original name of the worksheet.

Make sense??
 
Upvote 0
To reference a sheet by specific name( e.g. Sheet1), try something like...
With Sheets("Sheet1")

To reference a sheet by tab position, try something like...
With Sheets(1)

To reference a sheet's original code name (not its tab name), try something like this...
With Sheet1
 
Last edited:
Upvote 0

Forum statistics

Threads
1,206,711
Messages
6,074,465
Members
446,071
Latest member
gaborfreeman

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top