![]() |
Help creating a proper loop
I would like a user to select rows in a worksheet called "Inventory" (they
will be non-continuous) and then create a For..Next loop (or whatever works best) based on the rows (or just row number), so I can copy and format select cells from each row in another worksheet called "Labels". I'm not sure how to do this, either with an array or by looping thru the rows selected. Also, I need a check so if nothing has been selected they get an error message. For the selections, will the user need to select the entire row (1:1, 5:5, 7:7, etc) or if they just ctrl select A1, A5, A7, A11, etc will this work too? Thanks in advance! |
Help creating a proper loop
No need for a loop:
Selection.EntireRow.Copy worksheets("Labels").Range("A2") Application.CutCopyMode = False The entire rows need not be selected. __________________________________________________ _____________________ "Seth" wrote in message ... I would like a user to select rows in a worksheet called "Inventory" (they will be non-continuous) and then create a For..Next loop (or whatever works best) based on the rows (or just row number), so I can copy and format select cells from each row in another worksheet called "Labels". I'm not sure how to do this, either with an array or by looping thru the rows selected. Also, I need a check so if nothing has been selected they get an error message. For the selections, will the user need to select the entire row (1:1, 5:5, 7:7, etc) or if they just ctrl select A1, A5, A7, A11, etc will this work too? Thanks in advance! |
Help creating a proper loop
Thanks Vasant, but I don't want to copy all the contents from each row, just
certain cells and then reformat them on a new worksheet. "Vasant Nanavati" wrote: No need for a loop: Selection.EntireRow.Copy worksheets("Labels").Range("A2") Application.CutCopyMode = False The entire rows need not be selected. __________________________________________________ _____________________ "Seth" wrote in message ... I would like a user to select rows in a worksheet called "Inventory" (they will be non-continuous) and then create a For..Next loop (or whatever works best) based on the rows (or just row number), so I can copy and format select cells from each row in another worksheet called "Labels". I'm not sure how to do this, either with an array or by looping thru the rows selected. Also, I need a check so if nothing has been selected they get an error message. For the selections, will the user need to select the entire row (1:1, 5:5, 7:7, etc) or if they just ctrl select A1, A5, A7, A11, etc will this work too? Thanks in advance! |
Help creating a proper loop
I guess I would do the following (assuming the first cell in each relevant
row is selected): Dim c As Range, rng As Range, newrng As Range For Each c In Selection.Cells Set rng = c.Resize(, 5) 'this will encompass the first 5 cells in the row, for example If newrng Is Nothing Then Set newrng = rng Else Set newrng = Union(rng, newrng) End If Next newrng.Copy worksheets("Labels").Range("A2") Application.CutCopyMode = False Not tested so not 100% sure it will work as you want it to. __________________________________________________ _______________________ "Seth" wrote in message ... Thanks Vasant, but I don't want to copy all the contents from each row, just certain cells and then reformat them on a new worksheet. "Vasant Nanavati" wrote: No need for a loop: Selection.EntireRow.Copy worksheets("Labels").Range("A2") Application.CutCopyMode = False The entire rows need not be selected. __________________________________________________ _____________________ "Seth" wrote in message ... I would like a user to select rows in a worksheet called "Inventory" (they will be non-continuous) and then create a For..Next loop (or whatever works best) based on the rows (or just row number), so I can copy and format select cells from each row in another worksheet called "Labels". I'm not sure how to do this, either with an array or by looping thru the rows selected. Also, I need a check so if nothing has been selected they get an error message. For the selections, will the user need to select the entire row (1:1, 5:5, 7:7, etc) or if they just ctrl select A1, A5, A7, A11, etc will this work too? Thanks in advance! |
All times are GMT +1. The time now is 12:05 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com