PDA

View Full Version : Solved: VBA code launching problem



suddenflash
04-29-2012, 04:41 AM
Hi!

Earilier times I used to do some programming in basic and in pascal. Now time has passed and it is needed to write a little program.

Examining my knowledg and consulting with vba literature I wrote a test program but someway it doesnt launch, No error massages no sign of launched program on my excel sheet.

I have allowed all macroses to be used in excel. But I am out of knowledge to act on. This is just 1 purposeless progrem about to write numbers from 1 to 100 by dioganal on screen

Sub mingiasi()
Dim i As Integer
i = 0
Do While i = 100
i = i + 1

Range(i, i).Value = i
Loop
End Sub

I would preciate help and would be very greatful!

Suddenflash

omp001
04-29-2012, 05:44 AM
Hi. Try this way.

Sub mingiasi()
Dim i As Integer
i = 0
Do While i < 100
i = i + 1
Cells(i, i).Value = i
Loop
End Sub

suddenflash
04-29-2012, 06:12 AM
Thanks!

It works.

Paul_Hossler
04-29-2012, 08:58 AM
Welcome to the forum. Couple of suggestions


'good idea to include since it forces all variable to be declared
Option Explicit
Sub mingiasi()

'VBA uses Long now
Dim i As Long

'speeds macro by avoiding screen updating
Application.ScreenUpdating = False

'nothing wrong with a Do, but For/Next is useful also
For i = 1 To 100
'This will always refer to the active sheet
' which you might not want
' Cells(i, i).Value = i
'This will refer to Sheet1, regardless of which sheet is active
Worksheets("Sheet1").Cells(i, i).Value = i

Next i
Application.ScreenUpdating = True
End Sub


Paul

suddenflash
05-01-2012, 12:27 AM
Thanks!