Forum Discussion

gms4b's avatar
gms4b
Brass Contributor
Sep 04, 2019
Solved

help making a loop (to automate table formatting)

I am using excel VBA to automate table formatting. I have 24 tables to automate. I wrote the code with a macro then made some changes. It works fine (it autofills data on A3, E3, and F3, based on the...
  • gms4b 

     

    This should do what you are trying to achieve....

     

    Sub FormatTables()
    Dim c   As Long
    Dim lr  As Long
    Dim i   As Long
    
    Application.ScreenUpdating = False
    
    c = 1
    
    For i = 1 To 24
        lr = Cells(Rows.Count, c + 1).End(xlUp).Row
        If lr > 2 Then
            Cells(3, c).AutoFill Destination:=Range(Cells(3, c), Cells(lr, c))
            Cells(3, c + 4).AutoFill Destination:=Range(Cells(3, c + 4), Cells(lr, c + 4))
            Cells(3, c + 5).AutoFill Destination:=Range(Cells(3, c + 5), Cells(lr, c + 5))
        End If
        c = c + 18
    Next i
    
    Application.ScreenUpdating = True
    End Sub

Resources