ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Need Help With Creating A Loop (https://www.excelbanter.com/excel-programming/344127-need-help-creating-loop.html)

zero635[_8_]

Need Help With Creating A Loop
 

Below is a macro I am using. I need help with creating a loop once the
macro is ran it will move down to the next row and continue until it
reaches down to the row that is empty. This is the very first section
that my macro runs. I have to manually select the first row which is
B2:BG2. I want to be able to hit the button and it automatically
select B2:BG2 run all the way through the macro then start over again
but move down to C2:CG2 and so on. Also, I would like the loop to stop
once it reaches the last row that has data in it or stop as soon as it
reaches the first row that is empty. If any one could help I would
appreciate it. Thank You in advance.

Sub BAGAFEDEXEXPEDITES()
Application.ScreenUpdating = False
Set RangeName = Selection
Selection.Copy
Workbooks.Open ("L:\BAGA\02 PACKING SLIP TEMPLATES\BAGA BLANK
FEDEX.xls")
Windows("BAGA BLANK FEDEX.xls").Activate
Range("H15").Activate
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
Run "BAGAFEDPLTFRM"
End Sub

Thank You,
Zero


--
zero635
------------------------------------------------------------------------
zero635's Profile: http://www.excelforum.com/member.php...o&userid=24802
View this thread: http://www.excelforum.com/showthread...hreadid=480185


Tom Ogilvy

Need Help With Creating A Loop
 
You can loop through a range with

With Worksheets("Something")
set rng = .Range(Range("B2"),.Range("B2").End(xldown))
End With

for each cell in rng
set rw = cell.Resize(1,58)
. . .
Next

Other than that, there isn't much sensical in you post.

to go from B2:BG2 one would not move down, but would move right and expand
the selection by many columns:

? range("B2:BG2").Columns.Count
58
? range("C2:CG2").Columns.Count
83


the code you show doesn't seem to indicate a need to loop.

In my opinion, if you want help, you need to provide a much clearer
explanation of what you want to do.

--
Regards,
Tom Ogilvy

"zero635" wrote in
message ...

Below is a macro I am using. I need help with creating a loop once the
macro is ran it will move down to the next row and continue until it
reaches down to the row that is empty. This is the very first section
that my macro runs. I have to manually select the first row which is
B2:BG2. I want to be able to hit the button and it automatically
select B2:BG2 run all the way through the macro then start over again
but move down to C2:CG2 and so on. Also, I would like the loop to stop
once it reaches the last row that has data in it or stop as soon as it
reaches the first row that is empty. If any one could help I would
appreciate it. Thank You in advance.

Sub BAGAFEDEXEXPEDITES()
Application.ScreenUpdating = False
Set RangeName = Selection
Selection.Copy
Workbooks.Open ("L:\BAGA\02 PACKING SLIP TEMPLATES\BAGA BLANK
FEDEX.xls")
Windows("BAGA BLANK FEDEX.xls").Activate
Range("H15").Activate
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
Run "BAGAFEDPLTFRM"
End Sub

Thank You,
Zero


--
zero635
------------------------------------------------------------------------
zero635's Profile:

http://www.excelforum.com/member.php...o&userid=24802
View this thread: http://www.excelforum.com/showthread...hreadid=480185




zero635[_9_]

Need Help With Creating A Loop
 

The macro I use is for packing slip. Line B2:BG2 house the informatio
for the packing slip. It includes data such has address, name, number
etc. In the spreadsheet I am using I have say 15 lines 2 thru 16. Whe
I hit my macro it copies that line inserts it into the specifie
template and then does the rest of my programming, taking out lines
inserting, etc. But for me to do each line for each packing slip
have to highlight the individual lines and hit the macro button for i
to go through it. I am trying to automate to do the first packin
slip, move to the next line setup that one, go on to the next line
etc.. Everything that I have works so far, I didn't want to post al
my code because it is like 20 submodules (I think that is what they ar
called), but if I must then I will. Hope this makes any sense. I kno
what it is I am trying to do but explaining it is a different story.

Thanks,
Zer

--
zero63
-----------------------------------------------------------------------
zero635's Profile: http://www.excelforum.com/member.php...fo&userid=2480
View this thread: http://www.excelforum.com/showthread.php?threadid=48018


Tom Ogilvy

Need Help With Creating A Loop
 
Then it is as I said

Dim rng as Range
Dim sh as Worksheet
With Worksheets("PackingData")
set rng = .Range(Range("B2"),.Range("B2").End(xldown))
End With

for each cell in rng
set rw = cell.Resize(1,58)
set sh = activeSheet
Worksheets("PackingData").Select
rw.Select
' code to process the selected line/packing slip
Next

--
Regards,
Tom Ogilvy



"zero635" wrote in
message ...

The macro I use is for packing slip. Line B2:BG2 house the information
for the packing slip. It includes data such has address, name, number,
etc. In the spreadsheet I am using I have say 15 lines 2 thru 16. When
I hit my macro it copies that line inserts it into the specified
template and then does the rest of my programming, taking out lines,
inserting, etc. But for me to do each line for each packing slip I
have to highlight the individual lines and hit the macro button for it
to go through it. I am trying to automate to do the first packing
slip, move to the next line setup that one, go on to the next line,
etc.. Everything that I have works so far, I didn't want to post all
my code because it is like 20 submodules (I think that is what they are
called), but if I must then I will. Hope this makes any sense. I know
what it is I am trying to do but explaining it is a different story.

Thanks,
Zero


--
zero635
------------------------------------------------------------------------
zero635's Profile:

http://www.excelforum.com/member.php...o&userid=24802
View this thread: http://www.excelforum.com/showthread...hreadid=480185





All times are GMT +1. The time now is 01:38 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com