Repeating a Macro across an Entire Workbook

Nicole_Michelle01

Board Regular
Joined
Nov 9, 2005
Messages
50
I have 5 worksheets (Sheet1, Sheet2, Sheet3, Sheet4, Sheet5) and I want the following macro run for each worksheet:

Sub SetupFile()
For intcount = 1 To 256
If InStr(1, Cells(1, intcount), "userpsswd") > 0 Then
Cells(1, intcount).EntireColumn.Delete
End If
Next intcount
Columns("A:A").Select
Selection.Insert Shift:=xlToRight
Range("A1").Select
ActiveCell.FormulaR1C1 = "Review Notes"
Columns("A:A").Select
Selection.Columns.AutoFit
Columns("E:E").Select
Selection.Insert Shift:=xlToRight
Range("E1").Select
ActiveCell.FormulaR1C1 = "Dept."
End Sub

And also, if I want to add additional keywords to the InStr row ie "userpsswd" "psswd_expdate" "psswd_createdate", what would that look like?

thanks!
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
How about this code instead (looks for exact match only)?
Code:
Option Explicit
Sub SetupAllFiles()
Dim ws As Worksheet
Dim SearchWord, i As Integer

Application.ScreenUpdating = False
SearchWord = Array("keyword1", "keyword2", "keyword3", "keyword4")
For Each ws In ActiveWorkbook.Worksheets
    For i = 0 To UBound(SearchWord)
        Call SetupFile(SearchWord(i), ws)
    Next i
    ws.Columns("A:A").Insert Shift:=xlToRight
    ws.Range("A1").FormulaR1C1 = "Review Notes"
    ws.Columns("A:A").Columns.AutoFit
    ws.Columns("E:E").Insert Shift:=xlToRight
    ws.Range("E1").FormulaR1C1 = "Dept."
Next ws
Application.ScreenUpdating = True
End Sub


Sub SetupFile(KeywordPassed, ActiveWs As Worksheet)
Dim intcount As Integer

For intcount = 1 To 256
    If ActiveWs.Cells(1, intcount) = KeywordPassed Then
        ActiveWs.Cells(1, intcount).EntireColumn.Delete
    End If
Next intcount
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,951
Messages
6,122,449
Members
449,083
Latest member
Ava19

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