Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 55
Default Macro to insert Rows

Hi I have data in excel file that in Column "A" has ID numbers and
column "HC" has numbers for different categories that Group "A" ID
Numbers, these categories need to be in groups of 16 Rows if more that
16 Rows in each category then it should be in group of 32 rows or 48
and so on, the important thing is that I need a Macro to insert rows
in between this categories to make the rows equal to 16 or 32 or 48
and so on.

example I have the category numbered as "101" 2nd "104" 3rd 107.

1st group "101" has 12 ID numbers in Column "A" - need to insert 4
rows right after category 101 ends. Rows will = 16
2nd group "104" has 19 ID numbers in Column "A" - need to insert 13
rows right after category 104 ends. Rows will = 32
3rd group "107" has 38 ID numbers in Column "A" - need to insert 10
rows right after category 107 ends. Rows will = 48

I hope I was able to explain clearly, if any questions let me know....
I would appreciate for any help
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 293
Default Macro to insert Rows

Hi marc,

What is the purpose?

Inserting rows is easy enough, but there may be a better way to achieve what you want. If, for example, you only want a single
category to appear on each page of a printout, inserting hard pagebreaks should suffice. If it's because of the way a particular
formula works, then a different formula might be more appropriate.

--
Cheers
macropod
[MVP - Microsoft Word]


wrote in message ...
Hi I have data in excel file that in Column "A" has ID numbers and
column "HC" has numbers for different categories that Group "A" ID
Numbers, these categories need to be in groups of 16 Rows if more that
16 Rows in each category then it should be in group of 32 rows or 48
and so on, the important thing is that I need a Macro to insert rows
in between this categories to make the rows equal to 16 or 32 or 48
and so on.

example I have the category numbered as "101" 2nd "104" 3rd 107.

1st group "101" has 12 ID numbers in Column "A" - need to insert 4
rows right after category 101 ends. Rows will = 16
2nd group "104" has 19 ID numbers in Column "A" - need to insert 13
rows right after category 104 ends. Rows will = 32
3rd group "107" has 38 ID numbers in Column "A" - need to insert 10
rows right after category 107 ends. Rows will = 48

I hope I was able to explain clearly, if any questions let me know....
I would appreciate for any help


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,124
Default Macro to insert Rows

Try this idea that makes a unique list of col a for col F and then uses that
to count and then insert rows.

Sub makeuniquelistandcount1()
Application.ScreenUpdating = False

mc = "a"
lr = Cells(rows.Count, mc).End(xlUp).Row
With Range("A1:A" & lr)
.AdvancedFilter Action:=xlFilterInPlace, Unique:=True
.Copy Range("F1")
Application.CutCopyMode = False
ActiveSheet.ShowAllData
End With

flr = Cells(rows.Count, "f").End(xlUp).Row
For i = flr To 2 Step -1
Cells(i, "g") = Application.CountIf(Range("a2:a" & lr), Cells(i, "f"))
mr = Columns("A").Find(Cells(i, "f"), After:=Cells(lr, "a"),
LookIn:=xlValues, LookAt _
:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
'MsgBox mr
Set mycell = Cells(i, "g")
'MsgBox mycell

Select Case mycell
Case 32 To 48: x = 48 - mycell
Case 16 To 32: x = 36 - mycell
Case 1 To 16: x = 16 - mycell
Case Else
End Select
Range(Cells(mr, "a"), Cells(mr + x - 1, "a")).EntireRow.Insert
'MsgBox x
Next i

Application.ScreenUpdating = True
End Sub

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

wrote in message
...
Hi I have data in excel file that in Column "A" has ID numbers and
column "HC" has numbers for different categories that Group "A" ID
Numbers, these categories need to be in groups of 16 Rows if more that
16 Rows in each category then it should be in group of 32 rows or 48
and so on, the important thing is that I need a Macro to insert rows
in between this categories to make the rows equal to 16 or 32 or 48
and so on.

example I have the category numbered as "101" 2nd "104" 3rd 107.

1st group "101" has 12 ID numbers in Column "A" - need to insert 4
rows right after category 101 ends. Rows will = 16
2nd group "104" has 19 ID numbers in Column "A" - need to insert 13
rows right after category 104 ends. Rows will = 32
3rd group "107" has 38 ID numbers in Column "A" - need to insert 10
rows right after category 107 ends. Rows will = 48

I hope I was able to explain clearly, if any questions let me know....
I would appreciate for any help


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 55
Default Macro to insert Rows

Thanks Don, I tried the code but if gives an error @ "mr =
Columns("HB").Find(Cells(i, "HC"), After:=Cells(lr, "a"),"
also in Column "HC" I have unique numbers that separate the groups, is
it necessary to insert additional Columns (f)

Thanks,






On Aug 16, 6:57*am, "Don Guillett" wrote:
Try this idea that makes a unique list of col a for col F and then uses that
to count and theninsertrows.

Sub makeuniquelistandcount1()
Application.ScreenUpdating = False

mc = "a"
lr = Cells(rows.Count, mc).End(xlUp).Row
With Range("A1:A" & lr)
*.AdvancedFilter Action:=xlFilterInPlace, Unique:=True
*.Copy Range("F1")
Application.CutCopyMode = False
ActiveSheet.ShowAllData
End With

flr = Cells(rows.Count, "f").End(xlUp).Row
For i = flr To 2 Step -1
Cells(i, "g") = Application.CountIf(Range("a2:a" & lr), Cells(i, "f"))
mr = Columns("A").Find(Cells(i, "f"), After:=Cells(lr, "a"),
LookIn:=xlValues, LookAt _
* * * * :=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
* 'MsgBox mr
Set mycell = Cells(i, "g")
* 'MsgBox mycell

Select Case mycell
Case 32 To 48: x = 48 - mycell
Case 16 To 32: x = 36 - mycell
Case 1 To 16: x = 16 - mycell
Case Else
End Select
Range(Cells(mr, "a"), Cells(mr + x - 1, "a")).EntireRow.Insert
* 'MsgBox x
Next i

Application.ScreenUpdating = True
End Sub

--
Don Guillett
Microsoft MVP Excel
SalesAid Software
wrote in message

...



Hi I have data in excel file that in Column "A" has ID numbers and
column "HC" has numbers for different categories that Group "A" ID
Numbers, these categories need to be in groups of 16Rowsif more that
16Rowsin each category then it should be in group of 32rowsor 48
and so on, the important thing is that I need a Macro toinsertrows
in between this categories to make therowsequal to 16 or 32 or 48
and so on.


example I have the category numbered as "101" 2nd "104" 3rd 107.


1st group "101" has 12 ID numbers in Column "A" - need toinsert4
rowsright after category 101 ends.Rowswill = 16
2nd group "104" has 19 ID numbers in Column "A" - need toinsert13
rowsright after category 104 ends.Rowswill = 32
3rd group "107" has 38 ID numbers in Column "A" - need toinsert10
rowsright after category 107 ends.Rowswill = 48


I hope I was able to explain clearly, if any questions let me know....
I would appreciate for any help- Hide quoted text -


- Show quoted text -


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,124
Default Macro to insert Rows


If desired, send your file along with snippets of these posts to my address
below.

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

wrote in message
...
Thanks Don, I tried the code but if gives an error @ "mr =
Columns("HB").Find(Cells(i, "HC"), After:=Cells(lr, "a"),"
also in Column "HC" I have unique numbers that separate the groups, is
it necessary to insert additional Columns (f)

Thanks,






On Aug 16, 6:57 am, "Don Guillett" wrote:
Try this idea that makes a unique list of col a for col F and then uses
that
to count and theninsertrows.

Sub makeuniquelistandcount1()
Application.ScreenUpdating = False

mc = "a"
lr = Cells(rows.Count, mc).End(xlUp).Row
With Range("A1:A" & lr)
.AdvancedFilter Action:=xlFilterInPlace, Unique:=True
.Copy Range("F1")
Application.CutCopyMode = False
ActiveSheet.ShowAllData
End With

flr = Cells(rows.Count, "f").End(xlUp).Row
For i = flr To 2 Step -1
Cells(i, "g") = Application.CountIf(Range("a2:a" & lr), Cells(i, "f"))
mr = Columns("A").Find(Cells(i, "f"), After:=Cells(lr, "a"),
LookIn:=xlValues, LookAt _
:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
'MsgBox mr
Set mycell = Cells(i, "g")
'MsgBox mycell

Select Case mycell
Case 32 To 48: x = 48 - mycell
Case 16 To 32: x = 36 - mycell
Case 1 To 16: x = 16 - mycell
Case Else
End Select
Range(Cells(mr, "a"), Cells(mr + x - 1, "a")).EntireRow.Insert
'MsgBox x
Next i

Application.ScreenUpdating = True
End Sub

--
Don Guillett
Microsoft MVP Excel
SalesAid Software
wrote in message

...



Hi I have data in excel file that in Column "A" has ID numbers and
column "HC" has numbers for different categories that Group "A" ID
Numbers, these categories need to be in groups of 16Rowsif more that
16Rowsin each category then it should be in group of 32rowsor 48
and so on, the important thing is that I need a Macro toinsertrows
in between this categories to make therowsequal to 16 or 32 or 48
and so on.


example I have the category numbered as "101" 2nd "104" 3rd 107.


1st group "101" has 12 ID numbers in Column "A" - need toinsert4
rowsright after category 101 ends.Rowswill = 16
2nd group "104" has 19 ID numbers in Column "A" - need toinsert13
rowsright after category 104 ends.Rowswill = 32
3rd group "107" has 38 ID numbers in Column "A" - need toinsert10
rowsright after category 107 ends.Rowswill = 48


I hope I was able to explain clearly, if any questions let me know....
I would appreciate for any help- Hide quoted text -


- Show quoted text -




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
MACRO TO INSERT ROWS K[_2_] Excel Programming 6 February 15th 08 04:20 PM
Insert rows macro leonidas[_17_] Excel Programming 1 June 24th 06 12:38 AM
asking again, macro to insert rows Luke Excel Worksheet Functions 12 September 18th 05 06:32 PM
Insert Rows Macro Todd Excel Programming 4 April 2nd 04 09:48 PM
macro to insert rows. Todd[_5_] Excel Programming 2 September 27th 03 11:09 PM


All times are GMT +1. The time now is 10:19 AM.

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

About Us

"It's about Microsoft Excel"