Modify VBA Code select specific sheet instead of sequence

LNG2013

Active Member
Joined
May 23, 2011
Messages
466
How can I modify the below code to run on worksheet "Week1" instead of the 4th worksheet in?


Code:
Sub RemoveColWeek1sheet()
Dim ColNo As Integer
Dim rng As Range
'The range below specifies the worksheet from count order of left to right
'Need to change this
Set rng = ThisWorkbook.Sheets(4).UsedRange
For ColNo = rng.Columns.Count To 1 Step -1
Select Case rng.Cells(1, ColNo)
Case "Date", "Account", "Stock", "known"

'Take No Action
Case Else 'Delete the Column
rng.Columns(ColNo).Delete
End Select
Next ColNo
End Sub
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.

Forum statistics

Threads
1,225,071
Messages
6,182,676
Members
453,132
Latest member
nsnodgrass73

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