Macro to find name and delete Column in every workbook

tonywatsonhelp

Well-known Member
Joined
Feb 24, 2014
Messages
3,210
Office Version
  1. 365
  2. 2019
  3. 2016
Platform
  1. Windows
HI Everyone,

I need a macro that can do this,

When run,

Go To Every Visable Sheet, Look for The Name "Tony Smith" in Row 8, (there will be only 1) then delete the entire Column
if the sheet does not have that name go to next sheet

Please help if you can

Tony
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
How about
Code:
Sub delCol()
   Dim ws As Worksheet
   Dim Fnd As Range
   
   For Each ws In Worksheets
      Set Fnd = ws.Rows(8).find("Tony Smith", , , xlWhole, , , False, , False)
      If Not Fnd Is Nothing Then Columns(Fnd.Column).Delete
   Next ws
End Sub
 
Upvote 0
Glad to help & thanks for the feedback.

I've just noticed that you only wanted this to work on visible sheets, so I've changed it for that
Code:
Sub delCol()
   Dim ws As Worksheet
   Dim Fnd As Range
   
   For Each ws In Worksheets
      If ws.Visible = xlSheetVisible Then
         Set Fnd = ws.Rows(8).find("Tony Smith", , , xlWhole, , , False, , False)
         If Not Fnd Is Nothing Then Columns(Fnd.Column).Delete
      End If
   Next ws
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,894
Messages
6,175,250
Members
452,623
Latest member
Techenthusiast

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