0

is there a way to write a for loop to change the cell row as well as the variable Mat1 to Mat2 in an ascending manner?

.Cells(4, 30) = frmProjectCost.Mat1.Value
.Cells(5, 30) = frmProjectCost.Mat2.Value
.Cells(6, 30) = frmProjectCost.Mat3.Value
.Cells(7, 30) = frmProjectCost.Mat4.Value
.Cells(8, 30) = frmProjectCost.Mat5.Value
.Cells(9, 30) = frmProjectCost.Mat6.Value
.Cells(10, 30) = frmProjectCost.Mat7.Value
.Cells(11, 30) = frmProjectCost.Mat8.Value
.Cells(12, 30) = frmProjectCost.Mat9.Value
.Cells(13, 30) = frmProjectCost.Mat10.Value
.Cells(14, 30) = frmProjectCost.Mat11.Value
.Cells(15, 30) = frmProjectCost.Mat12.Value
.Cells(16, 30) = frmProjectCost.Mat13.Value
.Cells(17, 30) = frmProjectCost.Mat14.Value
.Cells(18, 30) = frmProjectCost.Mat15.Value
braX
  • 11,506
  • 5
  • 20
  • 33
Beese
  • 1
  • 1
    Related: https://stackoverflow.com/questions/11622648/using-a-for-loop-to-call-consecutive-variable-names-ie-car1-car2-car10-in – DecimalTurn Jul 22 '20 at 02:47

1 Answers1

3

Try something like:

Option Explicit

Private Sub FormLoop()

    Dim Counter As Long
    
    For Counter = 1 To 15
        ActiveSheet.Cells(Counter + 3, 30) = frmProjectCost.Controls("Mat" & Counter).Value
    Next

End Sub
TechnoDabbler
  • 1,245
  • 1
  • 6
  • 12