Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
Tom
 
Posts: n/a
Default Inserting a row (update)

I am currently using this VBA, but would like for it to insert (2) rows
instead of (1), how can I do that?

TFTH,
Tom


Sub InsertRows()

StartRow = 2 'Change the 2 to the row actual data start
DataColumn = 5 'Change the 1 to the column where your data is

i = StartRow + 1
While Cells(i, DataColumn) < ""
If Cells(i, DataColumn) < Cells(i - 1, DataColumn) Then
Cells(i, DataColumn).EntireRow.Insert
i = i + 1
End If
i = i + 1
Wend
End Sub

  #2   Report Post  
Posted to microsoft.public.excel.misc
Dave Peterson
 
Posts: n/a
Default Inserting a row (update)

Sometimes life gets a lot easier if you start at the bottom and work your way up
to the top.

Option Explicit
Sub InsertRows()

Dim StartRow As Long
Dim DataColumn As Long
Dim LastRow As Long
Dim iRow As Long

With ActiveSheet
StartRow = 2
DataColumn = 5
LastRow = .Cells(.Rows.Count, DataColumn).End(xlUp).Row

For iRow = LastRow To StartRow Step -1
If .Cells(iRow, DataColumn).Value _
= .Cells(iRow - 1, DataColumn).Value Then
'do nothing
Else
.Rows(iRow).Resize(2).Insert
End If
Next iRow
End With
End Sub

Tom wrote:

I am currently using this VBA, but would like for it to insert (2) rows
instead of (1), how can I do that?

TFTH,
Tom

Sub InsertRows()

StartRow = 2 'Change the 2 to the row actual data start
DataColumn = 5 'Change the 1 to the column where your data is

i = StartRow + 1
While Cells(i, DataColumn) < ""
If Cells(i, DataColumn) < Cells(i - 1, DataColumn) Then
Cells(i, DataColumn).EntireRow.Insert
i = i + 1
End If
i = i + 1
Wend
End Sub


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.misc
Tom
 
Posts: n/a
Default Inserting a row (update)

Worked perfectly!
Thanks.

"Dave Peterson" wrote:

Sometimes life gets a lot easier if you start at the bottom and work your way up
to the top.

Option Explicit
Sub InsertRows()

Dim StartRow As Long
Dim DataColumn As Long
Dim LastRow As Long
Dim iRow As Long

With ActiveSheet
StartRow = 2
DataColumn = 5
LastRow = .Cells(.Rows.Count, DataColumn).End(xlUp).Row

For iRow = LastRow To StartRow Step -1
If .Cells(iRow, DataColumn).Value _
= .Cells(iRow - 1, DataColumn).Value Then
'do nothing
Else
.Rows(iRow).Resize(2).Insert
End If
Next iRow
End With
End Sub

Tom wrote:

I am currently using this VBA, but would like for it to insert (2) rows
instead of (1), how can I do that?

TFTH,
Tom

Sub InsertRows()

StartRow = 2 'Change the 2 to the row actual data start
DataColumn = 5 'Change the 1 to the column where your data is

i = StartRow + 1
While Cells(i, DataColumn) < ""
If Cells(i, DataColumn) < Cells(i - 1, DataColumn) Then
Cells(i, DataColumn).EntireRow.Insert
i = i + 1
End If
i = i + 1
Wend
End Sub


--

Dave Peterson

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
options to update automatic links Werner Rohrmoser Excel Worksheet Functions 0 November 10th 05 12:58 PM
Prompt to update links Werner Rohrmoser Links and Linking in Excel 0 November 3rd 05 09:47 AM
Update links prompt not wanted neeraj Excel Discussion (Misc queries) 5 September 23rd 05 06:34 PM
How can a formula in a cell automatically update when inserting a. stbookkeeper Excel Worksheet Functions 1 June 23rd 05 08:14 PM
Auto Update upon shifting, inserting or deleting Tracy B Excel Worksheet Functions 2 April 6th 05 08:37 PM


All times are GMT +1. The time now is 05:40 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"