You are here:

Excel/Row Height in Macro

Advertisement


Question
QUESTION: Dear Aidan,

Hi. I need your expertise; im new with macros.

I have below macro of adding blank rows.

I wish to specify the row height of these blank rows to be 10. how can i incorporate this in the macro?

Also i wish it to start adding rows from row 131; at the moment it does from row 1.

Thank you so much for your help.

Kauther

ANSWER: You didn't give me your macro, which isn't a problem, but I may have used alternative methods.  my method would be something like

   Dim N, looper
   N = Val(InputBox("how many rows to insert"))
   Application.ScreenUpdating = False
   For looper = 1 To N
       Rows("131:131").Select
       Selection.Insert Shift:=xlDown
   Next
   Rows("131:" & 131 + N).RowHeight = 10
   Application.ScreenUpdating = True


---------- FOLLOW-UP ----------

QUESTION: Dear Aidan,

Sorry.. i somehow forgot to indicate the macro i was using. Its as below,

Sub Insert_Blank_Rows()
Application.ScreenUpdating = False
Dim numRows As Integer
Dim r As Long
Dim rng As Range
numRows = 1
Set rng = ActiveSheet.UsedRange
For r = rng.Rows.Count To 1 Step -1
rng.Rows(r + 1).Resize(numRows).EntireRow.insert
Next r
Application.ScreenUpdating = True
End Sub

I had tried replacing ".Resize" with ".RowHeight = 10" initially and it had failed.

Thanks & regards.

Answer
I'm not 100% sure that this will do what you want but

Sub Insert_Blank_Rows()
Application.ScreenUpdating = False
Dim numRows As Integer
Dim r As Long
Dim rng As Range
numRows = 1
Set rng = ActiveSheet.UsedRange
For r = 131 + rng.Rows.Count To 131 Step -1
rng.Rows(r + 1).Resize(numRows).EntireRow.Insert
rng.Rows(r + 1).RowHeight = 10
Next r
Application.ScreenUpdating = True
End Sub


is my update to cover the requirements you mentioned - I'm not 100% clear what the macro is intended to do, so there may be a better way of achieving your needs?
About Excel
This topic answers questions related to Microsoft Excel spreadsheet (or workbook) stand-alone or Mircrosoft Office Excel including Excel 2003, Excel 2007, Office 2000, and Office XP. You can get Excel help on Excel formulas(or functions), Excell macros, charting in Excel, advanced features, and the general use of Excel. This does not provide a general Excel tutorial nor the basics of using a spreadsheet. It provides specific answers to using Microsoft Excel only. If you do not see your Excel question answered in this area then please ask an Excel question here

Excel

All Answers


Answers by Expert:


Ask Experts

Volunteer


Aidan Heritage

Expertise

I have provided first hand support since `95 for Microsoft Office majoring in Word and Excel - support for all versions from 2 onwards. I'm based in the UK, so please allow for time differences when asking me questions from other parts of the world!

Experience

My background is in the insurance industry and call centre areas, but have been called upon to provide many varied solutions.

Education/Credentials
I'm educated to UK A level standard, but as I left school some 30 years ago that is rather irrelevent - university of life has provided more of a background!

©2016 About.com. All rights reserved.