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

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
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,223,162
Messages
6,170,432
Members
452,326
Latest member
johnshaji

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