Bookmaster
Board Regular
- Joined
- Mar 22, 2014
- Messages
- 85
- Office Version
- 2021
- Platform
- Windows
Hi,
I have a problem with VBA in excel. My code works fine for every table except when I have just 2 rows then I have error. First row is filled with column names and second rows i filled with formulas for each column. So if I have more then 2 rows everything works fine, but when I have just 2 rows I have error.
Line when my VBA stops is:
What is wrong here please?
I am sure that it has something to do with just 2 rows
I have a problem with VBA in excel. My code works fine for every table except when I have just 2 rows then I have error. First row is filled with column names and second rows i filled with formulas for each column. So if I have more then 2 rows everything works fine, but when I have just 2 rows I have error.
Line when my VBA stops is:
Code:
Dim LR As Long LR = Cells.Find(What:="*", SearchDirection:=xlPrevious, SearchOrder:=xlByRows).Row
Range("E2").AutoFill Destination:=Range("E2:E" & LR)
Range("I2").AutoFill Destination:=Range("I2:I" & LR)
Range("K2").AutoFill Destination:=Range("K2:K" & LR)
Range("M2").AutoFill Destination:=Range("M2:M" & LR)
Range("O2").AutoFill Destination:=Range("O2:O" & LR)
Range("Q2").AutoFill Destination:=Range("Q2:Q" & LR)
Range("S2").AutoFill Destination:=Range("S2:S" & LR)
Range("U2").AutoFill Destination:=Range("U2:U" & LR)
Range("W2").AutoFill Destination:=Range("W2:W" & LR)
Range("Y2").AutoFill Destination:=Range("Y2:Y" & LR)
Range("AB2").AutoFill Destination:=Range("AB2:AB" & LR)
Range("AF2").AutoFill Destination:=Range("AF2:AF" & LR)
Range("AH2").AutoFill Destination:=Range("AH2:AH" & LR)
Range("AJ2").AutoFill Destination:=Range("AJ2:AJ" & LR)
Range("AL2").AutoFill Destination:=Range("AL2:AL" & LR)
Range("AN2").AutoFill Destination:=Range("AN2:AN" & LR)
Range("AP2").AutoFill Destination:=Range("AP2:AP" & LR)
Range("AR2").AutoFill Destination:=Range("AR2:AR" & LR)
Range("AT2").AutoFill Destination:=Range("AT2:AT" & LR)
Range("AV2").AutoFill Destination:=Range("AV2:AV" & LR)
Range("AX2").AutoFill Destination:=Range("AX2:AX" & LR)
Range("AZ2").AutoFill Destination:=Range("AZ2:AZ" & LR)
Range("I2").Select
End Sub
What is wrong here please?
I am sure that it has something to do with just 2 rows