ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Do Until ? I think (https://www.excelbanter.com/excel-programming/283055-do-until-i-think.html)

Wally Steadman[_3_]

Do Until ? I think
 
Hi all,
Just learning to do VBA in Excel and by making a macro I
can see what type of code to use, but I have been stumped
on this one. I am a sheet that lists values in the first
column and I have a macro that loops through those values
doing a DO UNTIL Loop but where it is messing up is I have
been putting the last entry in the column as "ENDFILE" so
I DO UNITL ENDFILE is reached, but that is inefficient as
it still adds a blank worksheet for the ENDFILE Row but
not sure how to get it to stop without adding that sheet
and I am sure it is simple

Example
1
A Dave
B Steve
C Paul
D Dan
E Tina
F Debbie
G Tanya
H ENDFILE

What I am doing is having the code add worksheets to the
workbook and each sheet is named Dave, Steve, Paul etc...
But tomorrow I can have More or Less names so I need it to
loop until the first blank cell I guess but don't know how
to identify that cell. Any help would be appreciated.

Wally Steadman

Tom Ogilvy

Do Until ? I think
 
Dim rng as Range
set rng = Cells(1,1)
do until isempty(rng)
worksheets.Add(After:=worksheets( _
worksheets.count)).Name = rng.Value
set rng = rng.offset(1,0)
Loop

Remove ENDFILE from the last cell.

--
Regards,
Tom Ogilvy

Wally Steadman wrote in message
...
Hi all,
Just learning to do VBA in Excel and by making a macro I
can see what type of code to use, but I have been stumped
on this one. I am a sheet that lists values in the first
column and I have a macro that loops through those values
doing a DO UNTIL Loop but where it is messing up is I have
been putting the last entry in the column as "ENDFILE" so
I DO UNITL ENDFILE is reached, but that is inefficient as
it still adds a blank worksheet for the ENDFILE Row but
not sure how to get it to stop without adding that sheet
and I am sure it is simple

Example
1
A Dave
B Steve
C Paul
D Dan
E Tina
F Debbie
G Tanya
H ENDFILE

What I am doing is having the code add worksheets to the
workbook and each sheet is named Dave, Steve, Paul etc...
But tomorrow I can have More or Less names so I need it to
loop until the first blank cell I guess but don't know how
to identify that cell. Any help would be appreciated.

Wally Steadman




Wally Steadman[_3_]

Do Until ? I think
 
Thanks Tom, appreciate the help.

-----Original Message-----
Dim rng as Range
set rng = Cells(1,1)
do until isempty(rng)
worksheets.Add(After:=worksheets( _
worksheets.count)).Name = rng.Value
set rng = rng.offset(1,0)
Loop

Remove ENDFILE from the last cell.

--
Regards,
Tom Ogilvy

Wally Steadman

wrote in message
...
Hi all,
Just learning to do VBA in Excel and by making a macro I
can see what type of code to use, but I have been

stumped
on this one. I am a sheet that lists values in the

first
column and I have a macro that loops through those

values
doing a DO UNTIL Loop but where it is messing up is I

have
been putting the last entry in the column as "ENDFILE"

so
I DO UNITL ENDFILE is reached, but that is inefficient

as
it still adds a blank worksheet for the ENDFILE Row but
not sure how to get it to stop without adding that sheet
and I am sure it is simple

Example
1
A Dave
B Steve
C Paul
D Dan
E Tina
F Debbie
G Tanya
H ENDFILE

What I am doing is having the code add worksheets to the
workbook and each sheet is named Dave, Steve, Paul

etc...
But tomorrow I can have More or Less names so I need it

to
loop until the first blank cell I guess but don't know

how
to identify that cell. Any help would be appreciated.

Wally Steadman



.



All times are GMT +1. The time now is 11:58 PM.

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