View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.programming
keepITcool keepITcool is offline
external usenet poster
 
Posts: 2,253
Default How to Make a Loop count by 1% not 1

Jim,

note that writing Format(1.23,"%") it will not
work in situations where users have a comma as decimal separator.

I think that a better way to do this would be:

Sub AlsoLoop()
Dim Cnt As Long
Dim NumToFill As Long

NumToFill = Worksheets(1).Range("a1")

ActiveCell.Resize(NumToFill).NumberFormat = "0.00%"
For Cnt = 1 To NumToFill
ActiveCell.Cells(Cnt, 1).Value = Application.Round(Cnt / NumToFill, 4)
Next Cnt

End Sub






--
keepITcool
| www.XLsupport.com | keepITcool chello nl | amsterdam


Jim Cone wrote :

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