• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

VB Code help

ammo4814

New Member
Hi ,

i want to wrire the below code :

if i have cell "a1" = 1 i want incremental increase for the amount in the cell (1,2,3,4......)
until the number reach 40 then back to number 1 and repeat the count (1,2,3,4.....40)

could you please help me for this.
 
Hi,

Try this.

Code:
Sub try()
Dim i As Integer
Range("a1").Select
For i = 1 To 2
  ActiveCell = Range("a1").Value
  ActiveCell.Offset(1).Select
    Do While ActiveCell.Offset(-1).Value < 40
      ActiveCell = ActiveCell.Offset(-1).Value + 1
      ActiveCell.Offset(1).Select
    Loop
Next i

End Sub

I have set it to repeat two times. You can change it to any number of times here -> For i = 1 To 2

Hope this helps.

Cheers,
BD
 
Dear ,

Thanks for your help , but i want to count and change number (1,2,3,....) in the same cell a1 .

Thanks
 
Here you go !!

Code:
Sub try()
dim a as Integer,b as Integer, i as Integer
a = Range("a1").Value
b = Range("a1").Value + 1
For i = 1 To 2
  Do While b < 41
  Range("a1") = Range("a1").Value & "," & b
  b = b + 1
  Loop
b = a
Next i
End Sub

Cheers,
BD
 
Dear ,
Sorry for disturbing . i think i explain my idea not clearly .
but the idea i want the number in the cell change ( 1 then 2 then 3 .....40)
when i wrote the code give me in the cell 1,2,3,4,5......
 
I guess this should do it. I am not sure why you would want to change in the same cell though.

Code:
Sub try()
dim a as integer, i as integer
a = Range("a1").Value

For i = 1 To 2
do while range("a1").value< 40
  Range("a1") = Range("a1").Value +1
Loop
Range("a1")=a
Next i
EndSub

Cheers,
Bd
 
Thanks , but i have one question i think the number changes so quickly can i make it change more slow ,
The idea of this iam going to do animated chart i think this will help me .
i attach the files iam working on . if u help me i will be thankfull .
 

Attachments

  • TestMacro.xlsm
    13.1 KB · Views: 0
  • Test.xls.xlsx
    21.1 KB · Views: 0
Hi,

You can use this.

Code:
Sub try()
Dim a As Integer, i As Integer
 a = Range("a1").Value

For i = 1 To 2
Do While Range("a1").Value < 40
  Application.Wait (Now() + TimeValue("00:00:01"))
  Range("a1") = Range("a1").Value + 1
Loop
 Application.Wait (Now() + TimeValue("00:00:01"))
 Range("a1") = a
Next i

End Sub

I am not sure what you mean by animated chart. Do you want the graph to show one day after another ?

Thanks,
BD
 
Back
Top