Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Loop through records

Hello everyone,
i am new to vba and excel. In column A i have 47000 rows, i want to
loop through this column and if cell1 does not equal cell2 i want to
add a row between cell1 and cell2. I cannot figure out how to do this..
can anyone help me please??/
Thanks,
Erin

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,339
Default Loop through records

Erin,
Try this (on some test data first!)

Sub InsertRows()

Dim lastrow as long, r as long

lastrow = Cells(Rows.Count, "A").End(xlUp).Row

For r = lastrow To 2 Step -1

If Cells(r, 1) < Cells(r - 1, 1) Then
Cells(r, 1).Insert shift:=xlDown
End If

Next r

End Sub

HTH

" wrote:

Hello everyone,
i am new to vba and excel. In column A i have 47000 rows, i want to
loop through this column and if cell1 does not equal cell2 i want to
add a row between cell1 and cell2. I cannot figure out how to do this..
can anyone help me please??/
Thanks,
Erin


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Loop through records

Ok but how do i insert a full row, i have 8 columns and i want to
insert the row across all of the columns.
Thanks so much!!!

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Loop through records

if you only want to insert a blank cell in column A (or whatever column you
adjust it to operate on), then you have a solution. I f you actually want
to insert a blank row, change

Cells(r,1).Insert Shift:=xldown
to

rows(r).Insert



--
Regards,
Tom Ogilvy


"Toppers" wrote in message
...
Erin,
Try this (on some test data first!)

Sub InsertRows()

Dim lastrow as long, r as long

lastrow = Cells(Rows.Count, "A").End(xlUp).Row

For r = lastrow To 2 Step -1

If Cells(r, 1) < Cells(r - 1, 1) Then
Cells(r, 1).Insert shift:=xlDown
End If

Next r

End Sub

HTH

" wrote:

Hello everyone,
i am new to vba and excel. In column A i have 47000 rows, i want to
loop through this column and if cell1 does not equal cell2 i want to
add a row between cell1 and cell2. I cannot figure out how to do this..
can anyone help me please??/
Thanks,
Erin




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Loop through records

THANKS!!!!!!!!!!!



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Loop through records

Sub InsertRows()
Do Until ActiveCell.Value = ""
If ActiveCell.Value < ActiveCell.Offset(1, 0).Value Then
ActiveCell.Offset(1, 0).Activate
Current_Row = ActiveCell.Row
Rows(Current_Row).Select
Selection.Insert Shift:=xlDown
ActiveCell.Offset(1, 0).Activate
Else
ActiveCell.Offset(1, 0).Activate
End If
Loop
End Sub

Try that out

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,339
Default Loop through records

Thanks Tom. The OP did say insert row so the error was mine!

"Tom Ogilvy" wrote:

if you only want to insert a blank cell in column A (or whatever column you
adjust it to operate on), then you have a solution. I f you actually want
to insert a blank row, change

Cells(r,1).Insert Shift:=xldown
to

rows(r).Insert



--
Regards,
Tom Ogilvy


"Toppers" wrote in message
...
Erin,
Try this (on some test data first!)

Sub InsertRows()

Dim lastrow as long, r as long

lastrow = Cells(Rows.Count, "A").End(xlUp).Row

For r = lastrow To 2 Step -1

If Cells(r, 1) < Cells(r - 1, 1) Then
Cells(r, 1).Insert shift:=xlDown
End If

Next r

End Sub

HTH

" wrote:

Hello everyone,
i am new to vba and excel. In column A i have 47000 rows, i want to
loop through this column and if cell1 does not equal cell2 i want to
add a row between cell1 and cell2. I cannot figure out how to do this..
can anyone help me please??/
Thanks,
Erin





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
Delete records when certain records have duplicate column data JVroom New Users to Excel 1 January 26th 09 06:23 PM
Advancing outer Loop Based on criteria of inner loop ExcelMonkey Excel Programming 1 August 15th 05 05:23 PM
Loop Function unable to loop Junior728 Excel Programming 1 July 28th 05 10:23 AM
Problem adding charts using Do-Loop Until loop Chris Bromley[_2_] Excel Programming 2 May 23rd 05 01:31 PM
HELP!!!! Can't stop a loop (NOT an infinite loop) TBA[_2_] Excel Programming 3 December 14th 03 03:33 PM


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