Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 77
Default Rows (i).Insert

I have the below Macro to insert a row between groups of customers. Is it
possible to specify the row height of the inserted row, without changing the
height of the other rows?

Dim lastrow As Long, i As Long
lastrow = Cells(Rows.Count, 1).End(xlUp).Row
For i = lastrow To 2 Step -1
If Cells(i, 1) < Cells(i - 1, 1) Then
Rows(i).Insert.RowHeight = 15
End If
Next
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Rows (i).Insert

Hi Josh,

Try:

'=============
Public Sub Tester()
Dim lastrow As Long, i As Long

lastrow = Cells(Rows.Count, 1).End(xlUp).Row
For i = lastrow To 2 Step -1
If Cells(i, 1) < Cells(i - 1, 1) Then
Rows(i).Insert
Rows(i).RowHeight = 15
End If
Next
End Sub
'<<=============


---
Regards,
Norman


"Josh O." wrote in message
...
I have the below Macro to insert a row between groups of customers. Is it
possible to specify the row height of the inserted row, without changing
the
height of the other rows?

Dim lastrow As Long, i As Long
lastrow = Cells(Rows.Count, 1).End(xlUp).Row
For i = lastrow To 2 Step -1
If Cells(i, 1) < Cells(i - 1, 1) Then
Rows(i).Insert.RowHeight = 15
End If
Next



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Rows (i).Insert

Hi Josh,

To avoid potential problems, it is always advisable
to be explicit.

Therefore, better would be:

'=============
Public Sub Tester()
Dim WB As Workbook
Dim SH As Worksheet

Set WB = ThisWorkbook '<<=== CHANGE
Set SH = WB.Sheets("Sheet3") '<<=== CHANGE
Dim lastrow As Long, i As Long

With SH
lastrow = .Cells(Rows.Count, 1).End(xlUp).Row
For i = lastrow To 2 Step -1
If .Cells(i, 1).value < Cells(i - 1, 1).value Then
.Rows(i).Insert
.Rows(i).RowHeight = 15
End If
Next i
End With
End Sub
'<<=============


---
Regards,
Norman


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
insert rows in a worksheet that do not change adjoining rows craigandmel Excel Discussion (Misc queries) 2 April 29th 08 10:26 PM
How do i insert blank rows between data that is thousands of rows paul.eatwell Excel Discussion (Misc queries) 5 April 14th 08 10:49 PM
Insert rows: Formats & formulas extended to additonal rows Twishlist Excel Worksheet Functions 0 October 22nd 07 04:23 AM
Insert page breaks every 50 rows but do not include hidden rows Martin[_21_] Excel Programming 5 March 12th 07 05:10 PM
How do I insert blank rows between rows in completed worksheet? bblue1978 Excel Discussion (Misc queries) 1 October 26th 06 07:02 PM


All times are GMT +1. The time now is 09:32 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"