Format rowheight starting at row x then every nth rows

Xtrimmer

New Member
Joined
Apr 28, 2011
Messages
33
I was wondering if there was a good way to format multiple row heigths at once. What I need is, starting at row 4 and then every 9th row thereafter for the whole sheet, format the row height to 37.5. Any ideas? Thanks!
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
That can be done with a simple little macro. It takes a minute or two to run:
Code:
Sub MyRowHeight()
 
    Dim i As Long
    Dim myLastRow As Long
    
    Application.ScreenUpdating = False
    
'   Set initial value
    i = 4
    
'   Find possible number of rows
    myLastRow = Rows.Count
    
'   Do for whole sheet
    Do Until i > myLastRow
        Rows(i).RowHeight = 37.5
        i = i + 9
    Loop
    
    Application.ScreenUpdating = True
 
End Sub
 
Upvote 0
Might be slightly faster without a loop...

Rich (BB code):
Sub test()
Dim srow As Long, rwcnt As Long
srow = 4 'Beginning Row
rwcnt = 9 'Interval (every x rows)
 
Rows(srow).RowHeight = 37.5
Range(srow & ":" & srow + rwcnt - 1).Copy
Range(srow + rwcnt & ":" & Rows.Count).PasteSpecial xlPasteFormats
End Sub


Although this copies all formats, not just the row heights.
But given the context, it seems you want that pattern anyway..
 
Upvote 0
Thanks so much to both solutions. I can actually use them both depending on whether I have data & formatting in the sheet already and only need row height or starting a new sheet when the faster all format copying will be just fine!!!
 
Upvote 0
jonmo1,

What new doctrine is this? One without loops?
I feel like someone who just saw fire for the first time.

Could you explain how this works?
 
Upvote 0
jonmo1,

What new doctrine is this? One without loops?
I feel like someone who just saw fire for the first time.

Could you explain how this works?


If you put some values in a couple cells, Say
A1 = A
A2 = B

Then copy A1:A2
Then highlight A3:A100
Then Paste

You will see it repeats A B A B A B etc... all the way down.


That's all my code does.
main difference is it is using pastespecial - formats
So only the formats are pasted (which includes row heights).

And it looks alot more complicated because it uses variables to determine which row to start in, and how many rows to copy.

But that's about it.
 
Upvote 0
I did know that about copy/paste but never thought to apply it like you did. I like simple, it works for me! Sometimes I over think stuff. Thanks for the answer.
 
Upvote 0

Forum statistics

Threads
1,224,586
Messages
6,179,729
Members
452,939
Latest member
WCrawford

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