Looking for a vba solution for Column width formatting

mikenelena

Board Regular
Joined
Mar 5, 2018
Messages
139
Office Version
  1. 365
Platform
  1. Windows
I have the first 8 columns in my sheet (A-H) set to desired widths.

Does anyone know of any easy way to assign subsequent blocks of 8 (I-P), then Q-X), etc. to widths matching the first 8?

In other words, A, I, & Q... would all be 17.57. B, J, R would all be 9.43...

Many thanks in advance!

....Mike
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
how many columns across are you going? if it's not too far you could just copy columns A-H and paste special column widths
 
Upvote 0
Thanks fhqwgads, but I've got 30 sheets with about 28 blocks per sheet. I'm hoping for something faster...
 
Upvote 0
maybe something like

Code:
Sub Macro3()

Dim i As Long

    Columns("A:H").Copy
For i = 1 To 400 Step 8

    Columns(i).PasteSpecial Paste:=xlPasteColumnWidths, Operation:=xlNone, _
        SkipBlanks:=False, Transpose:=False
Next i
End Sub

this should paste widths across 50 blocks of 8 columns hopefully
 
Upvote 0
fhqwgads ,

That worked perfectly! Thanks so much! I added a line for last column, and a couple other embellishments.

Code:
Sub Macro3()


Dim i As Long
Dim lastcol As Long
Dim ws As Worksheet


Set ws = ThisWorkbook.ActiveSheet


Application.ScreenUpdating = False


lastcol = ws.Cells(2, ws.Columns.Count).End(xlToLeft).Column


    Columns("A:H").Copy
For i = 1 To lastcol Step 8


    Columns(i).PasteSpecial Paste:=xlPasteColumnWidths, Operation:=xlNone, _
        SkipBlanks:=False, Transpose:=False
Next i


Application.CutCopyMode = False


Range("h14").Select


MsgBox "Finished"


End Sub

 
Upvote 0

Forum statistics

Threads
1,223,229
Messages
6,170,881
Members
452,364
Latest member
springate

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