Row Height VBA

steveuk87

Board Regular
Joined
Nov 25, 2013
Messages
78
HELP!!

I need to copy a form over from one sheet to another, i can do this perfectly, only problem is there is alot of formatting etc that i also need taking across.

This is all complete except the row heights... Column widths are fine, but the row heights i just cant get right.

My problem is the amount of data to copy across is variable, and also the data in each section is variable to i cant just preset the same gaps in row heights... is there an easy way with VBA?
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
I don't know what you mean by Form. If you mean copy a range and paste to another:
Code:
Sub RunCopyPasteAll()
    Dim rSource As Range, rTarget As Range, s As String
    Set rSource = Application.InputBox("Select Source Range to Copy from:", "Source Range", Type:=8)
    Set rTarget = Application.InputBox("Target Cell to Paste to:", "Target Cell", Type:=8)
    CopyPasteAll rSource, rTarget
End Sub

Sub CopyPasteAll(rSource As Range, rTarget As Range)
    Dim r As Long, c As Long
    
    Application.DisplayAlerts = False
    
    With rSource
        .Copy rTarget
        .Copy
        rTarget.PasteSpecial xlPasteColumnWidths
        For r = 1 To .Rows.Count
            rTarget.Rows(r).RowHeight = .Rows(r).RowHeight
        Next r
    End With
    
    Application.DisplayAlerts = True
    Application.CutCopyMode = False
End Sub
 
Upvote 0
Thanks for your response Kenneth, Unfortunately your solution didn't work but i have been able to solve it...

I used the following code to input the size of the rows into a cell:

Code:
Sub RowHeight()

r = 1
Do While r < 459
ActiveCell.Value = Rows(r).RowHeight
ActiveCell.Offset(1, 0).Select
r = r + 1
Loop

End Sub

after that i then changed the row heights in then new workbook with the following:

Code:
Range("A1").Select
r = 1
Do While ActiveCell <> ""
Rows(r).RowHeight = ActiveCell.Value
ActiveCell.Offset(1, 0).Select
r = r + 1
Loop

This does what i need now.
 
Upvote 0

Forum statistics

Threads
1,223,237
Messages
6,170,928
Members
452,366
Latest member
TePunaBloke

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