Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22,906
Default Do Until Loop not functioning properly

MB

total=Selection.Rows.Count is OK as is.

Try this..........

Sub countit()
Range("A1").Select
Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Select
total = Selection.Rows.Count
MsgBox total & " rows"
End Sub

Now add a bunch of rows to the worksheet.

Run again...........note number of rows.

Delete a bunch of rows.

Run again.....whoops! same number as above.

xlLastCell is not an accurate method of finding the "real" last cell.

See Debra Dalgleish's site for more on this.

http://www.contextures.on.ca/xlfaqApp.html#Unused


Gord Dibben MS Excel MVP

On Tue, 23 Jan 2007 13:57:02 -0800, MB wrote:

1. I thought that I was defining a variable that represented the total
number of rows in the worksheet (total = Selection.Rows.Count). How would I
accomplish that...do I have to Dim it?

2. Thanks for that tip about copying worksheets.

Thanks, Jim, for helping me on this one.

"Jim Thomlinson" wrote:

A couple of things I see....
1. Where do you define total. You are counting to some number called total
without defining it for us.

2. There is a known issue with copying worksheets...
http://support.microsoft.com/default...84&Product=xlw

--
HTH...

Jim Thomlinson


"MB" wrote:

I have a macro that is supposed to count how many rows are active in the
current worksheet and generate a new sheet for each record. For some reason,
it generates 55 sheets and stops. When I have 39 records, it generates too
many and when I have 307 records, it doesn't generate enough. What's up with
the 55?

Here's the code:

Range("A1").Select
Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Select
total = Selection.Rows.Count
Range("A1").Select
counter = 1
Do Until counter = total
counter = counter + 1
Sheets("Sheet1").Select
Sheets("Sheet1").Copy Befo=Sheets(1)
Range("C8:D12,C15:D17,C20:D22,C25:D27,A3:H3").Sele ct
Range("A3").Activate
Selection.Replace What:="2", Replacement:=counter
Range("A1").Select
Loop


Please help...signed...Confused!!!


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
My arrow keys do not seem to be functioning properly. Any ideas? paul44 Excel Discussion (Misc queries) 1 February 20th 10 12:51 AM
F2 key is not functioning properly [email protected] Excel Discussion (Misc queries) 4 May 9th 07 06:12 PM
Read Only Not Functioning Properly Shelagh Excel Discussion (Misc queries) 0 April 21st 06 10:24 AM
Excel 98 not functioning properly on formula Michael Smith Excel Programming 6 July 13th 05 01:41 AM
Workbooks.Open not functioning properly Intikhab Bashir Excel Programming 3 August 18th 04 11:55 AM


All times are GMT +1. The time now is 08:14 PM.

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

About Us

"It's about Microsoft Excel"