Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,071
Default How to Make a Loop count by 1% not 1

The OP is probably no longer interested, but this is vulnerable to
rounding errors. Use
ActiveCell.Offset(Cnt, 0).Value = StartVal + Cnt * Increment
'StartVal = StartVal + dblIncrement

Also, why put the values as text? Just set the entire range's
NumberFormat propery?

ActiveCell.resize(numtofill-1,1).numberformat="0.00%"

[None of the code above has been tested.]



--
Regards,

Tushar Mehta
www.tushar-mehta.com
Excel, PowerPoint, and VBA add-ins, tutorials
Custom MS Office productivity solutions

In article ,
XX says...
or
'-----------------------
Sub GoodLoop()
Dim Cnt As Double
Dim StartVal As Double
Dim NumToFill As Double
Dim dblIncrement As Double

NumToFill = Sheets("Control").Range("E17")
dblIncrement = 1 / NumToFill
StartVal = dblIncrement

For Cnt = 0 To NumToFill - 1
ActiveCell.Offset(Cnt, 0).Value = Format(StartVal, "0.00%")
StartVal = StartVal + dblIncrement
Next Cnt

End Sub
'---------------------------------

Jim Cone
San Francisco, USA




"MichaelC" wrote in message
...
I have a macro that performs a looped calculation stepping up the input value
by 1 for each count.
I want to use the same macro to perform the same looped calculation starting
at 1% and ending at 100%, but have been unsuccessful.
My power Programming book is silent on this. I would much appreciate any
help.
Here is my macro:
Sub GoodLoop()
StartVal = 1
NumToFill = Sheets("Control").Range("E17")
ActiveCell.Value = StartVal
For Cnt = 0 To NumToFill - 1
ActiveCell.Offset(Cnt, 0).Value = StartVal + Cnt
Next Cnt

End Sub

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
count rownumbers in loop TUNGANA KURMA RAJU Excel Discussion (Misc queries) 9 October 3rd 05 09:29 AM
loop count TUNGANA KURMA RAJU Excel Discussion (Misc queries) 2 October 1st 05 04:54 AM
Jump to the next count in a FOR Loop Hari Prasadh[_2_] Excel Programming 9 February 1st 05 04:21 PM
Help with macro to make it loop through coloums R Krishna Excel Programming 0 July 29th 03 04:54 PM


All times are GMT +1. The time now is 05:36 PM.

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

About Us

"It's about Microsoft Excel"