Adding columns to multiple worksheets

Salts

New Member
Joined
Aug 21, 2019
Messages
16
Trying to create a macro that will add 2 new columns A & B with headers to each sheet in workbook.
This code works to add columns for all worksheets, but only puts the headers in the 1st worksheet.

Sub Insert_Columns()

Dim ws As Worksheet

For Each ws In ActiveWorkbook.Worksheets

On Error Resume Next

ws.[a:b].Insert

Range("A1").Select
ActiveCell.FormulaR1C1 = "Date Deleted: After Master Tab is Created"
Range("B1").Select
ActiveCell.FormulaR1C1 = "Date Added: After Master Tab is Created"

Next ws
End Sub
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
Try
Code:
Ws.Range("A1").Value = "Date Deleted: After Master Tab is Created"
Ws.Range("B1").Value = "Date Added: After Master Tab is Created"
 
Upvote 0
how about adding color to each of these headers?
I've tried adding ws. in front of each function but again it is only color coding the first worksheet.

ws.Range("A:A").Select
With Selection.Font
.Color = -16776961
.TintAndShade = 0
End With

ws.Range("B:B").Select
With Selection.Font
.Color = -11489280
.TintAndShade = 0
End With

ws.Range("A1:B1").Select
Selection.Font.Bold = True
ws.Range("1:1").EntireRow.AutoFit
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
.WrapText = True
End With
 
Upvote 0
You can only select cells on the activesheet, so you need to do it like
Code:
With Ws.Range("A:A").Font
   .Color = -16776961
   .TintAndShade = 0
End With
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,214,827
Messages
6,121,803
Members
449,048
Latest member
greyangel23

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