PDA

View Full Version : [SOLVED:] VBA Excel - For... next instruction



gvaladezmx
10-24-2023, 02:33 PM
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

rollis13
10-24-2023, 03:05 PM
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")

gvaladezmx
10-24-2023, 03:16 PM
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

gvaladezmx
10-24-2023, 03:17 PM
Thank you rollis13!, it works!. I really appreciate it!

Paul_Hossler
10-24-2023, 03:37 PM
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

rollis13
10-25-2023, 12:02 AM
@gvaladezmx, thanks for the positive feedback :thumb, glad having been of some help.