Help with macro

Mldeuser

Well-known Member
Joined
Dec 27, 2008
Messages
574
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

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
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,224,396
Messages
6,178,389
Members
452,844
Latest member
Shebl

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