#1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 3,101
Default Macro Help

Hello,
Could someone please help me with a macro that will insert a row between
Groups
of Numbers. I would like to be able to insert a row between =10000 and
<=19999,
=20000 and <=29999, =30000 and <=39999, =40000 and <=49999, =50000 and<=59999 and so on upto 100000. I export this from Quickbooks and have to insert rows manually


Thanks in advance for any help

Vender Parts UPC Item Description QTY
11003
15002
17000
18000
19000
19999
20000
21000
25000
26000
26010

  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 3,365
Default Macro Help

Mike, try this. It's setup as if your Vendor numbers are in column A. If
they are in another column, change the reference appropriately. Be sure that
the statement
Range("A3").Select
takes you to the second entry in the list of numbers (where your 15002 is in
your example) because it wants to look 1 row above that and at that row to
make the comparison. It also presumes that your list of Vendor Parts is
sorted as you have it he in ascending order, before beginning the
operation.

Sub InsertAt10K_Intervals()
Dim LastRowUsed As Long
Dim TestValue As Long

'assumes Vendor #s in column A
LastRowUsed = Range("A" & Rows.Count).End(xlUp).Row
TestValue = 19999
Range("A3").Select ' SECOND value in list
Application.Screenupdating = FALSE
Do Until TestValue 99999
If ActiveCell.Offset(-1,0) <= TestValue And _
ActiveCell.Value TestValue Then
'insert blank row & update values
Selection.EntireRow.Insert
LastRowUsed=LastRowUsed + 1
TestValue = TestValue + 10000
End If
ActiveCell.Offset(1, 0).Activate
If ActiveCell.Row LastRowUsed Then
Exit Do
End If
Loop
End Sub

"Mike" wrote:

Hello,
Could someone please help me with a macro that will insert a row between
Groups
of Numbers. I would like to be able to insert a row between =10000 and
<=19999,
=20000 and <=29999, =30000 and <=39999, =40000 and <=49999, =50000 and<=59999 and so on upto 100000. I export this from Quickbooks and have to insert rows manually


Thanks in advance for any help

Vender Parts UPC Item Description QTY
11003
15002
17000
18000
19000
19999
20000
21000
25000
26000
26010

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 694
Default Macro Help

Mike

Try this: I assume it is run on the active sheet and the data starts on row
2 with headings on row 1.

Option Explicit

Sub insertrows()

Const cdInc As Double = 10000
Const clRowStart As Long = 2
Dim lrow As Long
Dim dVal As Double

lrow = clRowStart
dVal = cdInc * 2

With ActiveSheet
Do While lrow < .Cells.Rows.Count
If .Cells(lrow, 1) = "" Then
Exit Sub
End If
If .Cells(lrow, 1).Value dVal Then
.Rows(lrow - 1).Insert
dVal = dVal + cdInc
lrow = lrow + 2
Else
lrow = lrow + 1
End If
Loop
End With
End Sub

--
Hope this helps
Martin Fishlock, Bangkok, Thailand
Please do not forget to rate this reply.


"Mike" wrote:

Hello,
Could someone please help me with a macro that will insert a row between
Groups
of Numbers. I would like to be able to insert a row between =10000 and
<=19999,
=20000 and <=29999, =30000 and <=39999, =40000 and <=49999, =50000 and<=59999 and so on upto 100000. I export this from Quickbooks and have to insert rows manually


Thanks in advance for any help

Vender Parts UPC Item Description QTY
11003
15002
17000
18000
19000
19999
20000
21000
25000
26000
26010

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1,726
Default Macro Help

Public Sub ProcessData()
Const TEST_COLUMN As String = "A" '<=== change to suit
Dim i As Long
Dim iLastRow As Long
Dim cell As Range
Dim sh As Worksheet

Application.ScreenUpdating = False

With ActiveSheet

iLastRow = .Cells(.Rows.Count, TEST_COLUMN).End(xlUp).Row
For i = iLastRow To 3 Step -1
If .Cells(i, TEST_COLUMN).Value \ 10000 < _
.Cells(i - 1, TEST_COLUMN).Value \ 10000 Then
.Rows(i).Insert
End If
Next i

End With

Application.ScreenUpdating = True

End Sub

--
---
HTH

Bob

(change the xxxx to gmail if mailing direct)


"Mike" wrote in message
...
Hello,
Could someone please help me with a macro that will insert a row between
Groups
of Numbers. I would like to be able to insert a row between =10000 and
<=19999,
=20000 and <=29999, =30000 and <=39999, =40000 and <=49999, =50000
and<=59999 and so on upto 100000. I export this from Quickbooks and have
to insert rows manually


Thanks in advance for any help

Vender Parts UPC Item Description QTY
11003
15002
17000
18000
19000
19999
20000
21000
25000
26000
26010



  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 3,101
Default Macro Help

JLatham Thankyou
I Canged the Range to ("A4") works great. Also is it posible to say If QTY =
0 then
cut row and insert that row at the bottom


"JLatham" wrote:

Mike, try this. It's setup as if your Vendor numbers are in column A. If
they are in another column, change the reference appropriately. Be sure that
the statement
Range("A3").Select
takes you to the second entry in the list of numbers (where your 15002 is in
your example) because it wants to look 1 row above that and at that row to
make the comparison. It also presumes that your list of Vendor Parts is
sorted as you have it he in ascending order, before beginning the
operation.

Sub InsertAt10K_Intervals()
Dim LastRowUsed As Long
Dim TestValue As Long

'assumes Vendor #s in column A
LastRowUsed = Range("A" & Rows.Count).End(xlUp).Row
TestValue = 19999
Range("A3").Select ' SECOND value in list
Application.Screenupdating = FALSE
Do Until TestValue 99999
If ActiveCell.Offset(-1,0) <= TestValue And _
ActiveCell.Value TestValue Then
'insert blank row & update values
Selection.EntireRow.Insert
LastRowUsed=LastRowUsed + 1
TestValue = TestValue + 10000
End If
ActiveCell.Offset(1, 0).Activate
If ActiveCell.Row LastRowUsed Then
Exit Do
End If
Loop
End Sub

"Mike" wrote:

Hello,
Could someone please help me with a macro that will insert a row between
Groups
of Numbers. I would like to be able to insert a row between =10000 and
<=19999,
=20000 and <=29999, =30000 and <=39999, =40000 and <=49999, =50000 and<=59999 and so on upto 100000. I export this from Quickbooks and have to insert rows manually


Thanks in advance for any help

Vender Parts UPC Item Description QTY
11003
15002
17000
18000
19000
19999
20000
21000
25000
26000
26010

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
error when running cut & paste macro Otto Moehrbach Excel Worksheet Functions 4 August 9th 06 01:49 PM
Compiling macro based on cell values simonsmith Excel Discussion (Misc queries) 1 May 16th 06 08:31 PM
Search, Copy, Paste Macro in Excel [email protected] Excel Worksheet Functions 0 January 3rd 06 06:51 PM
Closing File Error jcliquidtension Excel Discussion (Misc queries) 4 October 20th 05 12:22 PM
Highlight Range - wrong macro, please edit. Danny Excel Worksheet Functions 8 October 19th 05 11:11 PM


All times are GMT +1. The time now is 12:48 PM.

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"