VBA to Insert column in multiple sheets

Hellamint

New Member
Joined
Jun 12, 2009
Messages
8
Good Morning all,

I have a workbook with multiple worksheets. Within each worksheet is a column heading named "CurrencyDesc" (located in a different column in each sheet, and that will always change). I want to find "CurrencyDesc" and insert a column to the right of it. I have part of the code, but it only applies it to the first worksheet.



ActiveWorkbook.Sheets.Select

Selection.EntireColumn.Select

Cells.Find("CurrencyDesc").Select

ActiveCell.EntireColumn.Offset(0, 1).Insert



I need it to apply the find and insert to ALL of the worksheets. What am I missing?

THANK YOU IN ADVANCE!!!:)
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
Try this:-

for a = 1 to sheets.count
Sheets(a).Select

Selection.EntireColumn.Select

Cells.Find("CurrencyDesc").Select

ActiveCell.EntireColumn.Offset(0, 1).Insert

next
 
Upvote 0
You may get an error if there is no "CurrencyDesc" column in the worksheet.

Paste this in first line with in the macro:

on error resume next
 
Upvote 0
Code:
Sub InsertColumnx()
Dim WS As Worksheet
    For Each WS In Worksheets
        On Error Resume Next
        WS.Cells.Find("CurrencyDesc").EntireColumn.Offset(0, 1).Insert
    Next WS
End Sub
 
Upvote 0
Thank you so much Datsmart! Would you be so kind as to describe what each line in the code is doing for me?

MANY THANKS!!!
 
Upvote 0
I hope this can help:
Code:
Sub InsertColumnx()
Dim WS As Worksheet
    
    'Cycle through each worksheet in workbook
    For Each WS In Worksheets
        
        'If FIND function finds nothing, go to Next WS
        On Error Resume Next
        
        'If FIND function finds the text, insert a new column "offset" one column
        WS.Cells.Find("CurrencyDesc").EntireColumn.Offset(0, 1).Insert
    
    'Return to above "For" on next worksheet
    Next WS
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,101
Messages
6,170,116
Members
452,302
Latest member
TaMere

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