Seeking method to set row height of LastRow

auto.pilot

Well-known Member
Joined
Sep 27, 2007
Messages
734
Office Version
  1. 365
Platform
  1. Windows
Using Excel 2010, I am seeking a VBA method to set the row height of the LastRow

My last row is defined as ...

Code:
 LastRow = Range("B" & Rows.Count).End(xlUp).Row

I know how to paste to the last row, but the syntax or method to set the height escapes me. I've searched and can't find anything that matches this question.

Appreciate any thoughts.

Thanks

Jim
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Something like this:
Code:
    lastRow = Range("B" & Rows.Count).End(xlUp).Row
    Rows(lastRow).RowHeight = 25

Hint: If you forget the VBA code for things such as this, just use the Macro Recorder and record yourself setting the row height manually to see what that part needs to look like.
 
Last edited:
Upvote 0
Perfect. I knew the part about setting the height, but not how to ID the row. Thank you!
 
Upvote 0
You are welcome!

If you recorded yourself manually setting the height of some row, it would record something like:
Code:
    Rows("14:14").Select
    Selection.RowHeight = 25
which you can simplify to:
Code:
    Rows("14:14").RowHeight = 25

The code that you provide just captures a row number, and stores it in a variable named "lastRow".
So all you have to do is substitute in the name of the variable in place of the hard-coded row numbers.
 
Upvote 0
You make it sound so easy... but a novice like me put quotes around the variable (as one of many failed attempts)!

Code like this fails, which is exactly why I am here!

Code:
 Rows("LastRow").RowHeight = 25

and

Code:
 Rows("LastRow").Select

Thanks!

Jim
 
Upvote 0
I know there are people of many different skill levels here, so I often try to explain what I did to help them learn.

One thing that does often trip up VBA noobs is that anything enclosed in double-quotes is treated as literal text, so you never want to enclose variables in double-quotes.

A good way to illustrate it is to run this little macro which returns two Message Boxes and see what each returns:
Code:
Sub Test()


    Dim lastRow As Long
    lastRow = Range("B" & Rows.Count).End(xlUp).Row
    
    MsgBox lastRow
    MsgBox "lastRow"
    
End Sub
 
Upvote 0
Excellent! I understand the issue without even running the sample code. However, I never made the connection as you have so eloquently described it. Thank you very much!
 
Upvote 0
You are welcome.
Keep on Excel-ling!:)
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,021
Latest member
Justyna P

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