Consulting

Results 1 to 6 of 6

Thread: VBA Excel - For... next instruction

  1. #1

    VBA Excel - For... next instruction

    Hi, I'm trying to get cell values starting from A22.. and then A23, etc. each cycle from my for instruction
    The firt module is working fine, however with test1 module is writing all the time A22 value.

    Sub Create_RO()
    Dim total() As Variant
    Dim maximo As Long
    Dim i As Long
    maximo = Range("A21").Value
    ReDim total(1 To maximo)
    For i = 1 To maximo
         total(i) = i
    Next i
    total = Application.Transpose(total)
    Range("A22").Resize(UBound(total)).Value = total
    End Sub
    
    
    Sub test1()
    For x = 22 To (21 + Range("A21").Value)
    Cells(x, 2) = "MSAI0" & Range("D4") & "L" & Range("C18") & "0" & Range("A22") & "RO" & Range("J4") & Range("K4")
    Next
    End Sub
    Can you help me with this please?

    Thank you
    Last edited by Aussiebear; 10-24-2023 at 04:40 PM. Reason: Reduced the whitespace

  2. #2
    VBAX Contributor rollis13's Avatar
    Joined
    Jun 2013
    Location
    Cordenons
    Posts
    146
    Location
    If I correctly understood, use this line of code instead:
    Cells(x, 2) = "MSAI0" & Range("D4") & "L" & Range("C18") & "0" & Range("A" & x) & "RO" & Range("J4") & Range("K4")
    Difficult is not to know but to share what you know (Han Fei Tzu reworked)

  3. #3
    Quote Originally Posted by gvaladezmx View Post
    Hi, I'm trying to get cell values starting from A22.. and then A23, etc. each cycle from my for instruction
    The firt module is working fine, however with test1 module is writing all the time A22 value.

    Sub Create_RO()
    Dim total() As Variant
        Dim maximo As Long
        Dim i As Long
    maximo = Range("A21").Value
        ReDim total(1 To maximo)
    For i = 1 To maximo
            total(i) = i
        Next i
    total = Application.Transpose(total)
    Range("A22").Resize(UBound(total)).Value = total
    End Sub
    
    Sub test1()
    For x = 22 To (21 + Range("A21").Value)
    Cells(x, 2) = "MSAI0" & Range("D4") & "L" & Range("C18") & "0" & Range("A22") & "RO" & Range("J4") & Range("K4")
    Next
    End Sub
    Can you help me with this please?

    Thank you

  4. #4
    Thank you rollis13!, it works!. I really appreciate it!

  5. #5
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,765
    Location
    Quote Originally Posted by gvaladezmx View Post
    Thank you rollis13!, it works!. I really appreciate it!
    Good. Mark the thread [SOLVED] using Thread Tools above your first post and try to remember to use the [#] icon to add code tags around your macro to set it aff and to format it
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  6. #6
    VBAX Contributor rollis13's Avatar
    Joined
    Jun 2013
    Location
    Cordenons
    Posts
    146
    Location
    @gvaladezmx, thanks for the positive feedback , glad having been of some help.
    Difficult is not to know but to share what you know (Han Fei Tzu reworked)

Posting Permissions

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