Consulting

Results 1 to 5 of 5

Thread: Solved: VBA code launching problem

  1. #1

    Solved: VBA code launching problem

    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

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

    Range(i, i).Value = i
    Loop
    End Sub
    [/VBA]
    I would preciate help and would be very greatful!

    Suddenflash

  2. #2
    VBAX Regular
    Joined
    Aug 2011
    Posts
    87
    Location
    Hi. Try this way.

    [vba]Sub mingiasi()
    Dim i As Integer
    i = 0
    Do While i < 100
    i = i + 1
    Cells(i, i).Value = i
    Loop
    End Sub
    [/vba]
    Regards
    Osvaldo

  3. #3
    Thanks!

    It works.

  4. #4
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,711
    Location
    Welcome to the forum. Couple of suggestions

    [VBA]
    '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
    [/VBA]

    Paul

  5. #5
    Thanks!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •