Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
Hi,
A colleague has a spreadsheet with a list of 400 salon names in Column A. She wants to add a list of sub headings, also in Column A, beneath each salon name. There are 16 items on the list and one blank cell before the next salon name. I have written a Macro to copy the initial cells from below the first salon name (A2:A18) and insert them below the second salon name. Range("A2:A18").Select Selection.Copy Range("A20").Select Selection.Insert Shift:=xlDown ActiveWindow.SmallScroll Down:=-3 How do I now get this to insert it after each salon name? I hope someone can help! Many thanks, Richard Thorneycroft |
#2
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
After much trial and error doing a little more research I've come up
with this, for a test of just 8 salon names... Dim RowNdx As Long Dim Arr As Variant Dim StartRow As Long Dim EndRow As Long StartRow = 1 '<<< CHANGE to appropriate row number EndRow = 8 '<<< CHANGE to appropriate row number Arr = Application.Transpose(Array("Hair Service", "Hair Retail", "Total Hair", "Beauty Service", "Beauty Retail", "Total Beauty", "Total", "Colour Number", "Treatment Number", "Facial Number", "Waxing Number", "Hair Service Customer No", "Beauty Service Customer No", "Hair CF Count", "Beauty CF Count", "")) For RowNdx = StartRow + 1 To (EndRow) * 16 Step 17 Rows(RowNdx).Resize(16).Insert Cells(RowNdx, 1).Resize(16, 1).Value = Arr Next RowNdx Could some one let me know if this is correct, it seems to work fine on a test of 8 salon names, but I'm not sure if it's the best way of getting the job done. Cheers, Rich |
#3
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
Hi Rich,
Don't ask me why but I had to change EndRow = 8 to EndRow = 425 for all 400 salons to be done. Trial and error got me there. Loops are always hard to follow. To speed things up a bit I threw in "Application.ScreenUpdating = False" at the start to prevent all the screen flashing. It can be put anywhere in the code so long as it's before the Loop. Ken Johnson |
#4
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
You can determine a variable end row by
endrow=cells(rows.count,"a").end(xlup).row change the "a" to the column desired. -- Don Guillett SalesAid Software "Ken Johnson" wrote in message oups.com... Hi Rich, Don't ask me why but I had to change EndRow = 8 to EndRow = 425 for all 400 salons to be done. Trial and error got me there. Loops are always hard to follow. To speed things up a bit I threw in "Application.ScreenUpdating = False" at the start to prevent all the screen flashing. It can be put anywhere in the code so long as it's before the Loop. Ken Johnson |
#5
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
Thanks for that Don.
However I can't seem to get the endrow=cells(rows.count,"a").end(xlup).row line to fundtion correctly. My code looks like this and it leaves 23 salons not done. Sub InsertValuesBelowCells() ' ' Macro3 Macro ' Macro recorded 16/01/2006 by Rich T ' Dim RowNdx As Long Dim Arr As Variant Dim StartRow As Long Dim EndRow As Long Application.ScreenUpdating = False StartRow = 1 EndRow = Cells(Rows.Count, "A").End(xlUp).Row Arr = Application.Transpose(Array("Hair Service", "Hair Retail", "Total Hair", "Beauty Service", "Beauty Retail", "Total Beauty", "Total", "Colour Number", "Treatment Number", "Facial Number", "Waxing Number", "Hair Service Customer No", "Beauty Service Customer No", "Hair CF Count", "Beauty CF Count", "")) For RowNdx = StartRow + 1 To (EndRow) * 16 Step 17 Rows(RowNdx).Resize(16).Insert Cells(RowNdx, 1).Resize(16, 1).Value = Arr Next RowNdx ' End Sub |
#6
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
Hi Ken,
Thanks for the screen updating tip. However, I can't get it to run to the right place, it seems however I try it it always leaves 23 salons unfinished. I tried Don's suggestion below and your 425. I also tried other numbers, but still 23 lines were left untouched!? Any ideas where I am going wrong? Thanks again. Rich |
#7
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
Hi Guys,
Hust a little more info. The macro below works fine until the number of rows increases. I've tried it with up to 15 rows and it works fine, anything over that and it doesn't finish the range. It seems the more rows, the more it leaves untouched, but I can't see a pattern. With 16 rows it leaves 1 not done and the same with 30 rows. With 50 rows it leaves 3, but with 400 rows it leaves 23 not done?!? Dim RowNdx As Long Dim Arr As Variant Dim StartRow As Long Dim EndRow As Long Application.ScreenUpdating = False StartRow = 1 EndRow = Cells(Rows.Count, "A").End(xlUp).Row Arr = Application.Transpose(Array("Hair Service", "Hair Retail", "Total Hair", "Beauty Service", "Beauty Retail", "Total Beauty", "Total", "Colour Number", "Treatment Number", "Facial Number", "Waxing Number", "Hair Service Customer No", "Beauty Service Customer No", "Hair CF Count", "Beauty CF Count", "")) For RowNdx = StartRow + 1 To (EndRow) * 16 Step 17 Rows(RowNdx).Resize(16).Insert Cells(RowNdx, 1).Resize(16, 1).Value = Arr Next RowNdx |
#9
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
Hi Rich,
I can confirm the 23 undone salons using EndRow = Cells(Rows.Count,"A".End(xlUp).Row, however, I get all 400 salons done using EndRow = 425. Beats me what's going wrong at your end. I pasted the code from your last reply and just changed the EndRow. Ken Johnson |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Macro to coppy cells to certain rows depending on value in cell | Excel Discussion (Misc queries) | |||
How do I get macro to unmerge cells that have been previously merg | New Users to Excel | |||
Closing File Error | Excel Discussion (Misc queries) | |||
Insert Row before Macro Button | Excel Discussion (Misc queries) | |||
Copy/insert copied cells when protection is on... | Excel Worksheet Functions |