I am working on a macro to copy certain information from one worksheet to another.
I have a question concerning the autofill I used in the code below. Is it possible to only autofill to a certain range of rows depending on the amount of rows of worksheetA containing data instead of the manually inserted 'row 5000'?
Code so far included below
Thanks in advance.
Michiel
P.S. Don't mind all the select commands, I'm not really into all the VBA-programming and the data copying isn't that massive so the run-time is limited.
Sub WorksheetB()
'
' WorksheetB Macro
'
' Sneltoets: Ctrl+Shift+H
'
Sheets("WorksheetB").Select
Range("A1").Select
ActiveCell.FormulaR1C1 = "='WorksheetA'!RC"
Range("B1").Select
ActiveCell.FormulaR1C1 = "='WorksheetA'!RC"
Range("C1").Select
ActiveCell.FormulaR1C1 = "=IF('WorksheetA'!RC[6]>0,'WorksheetA'!RC[6],"""")"
Range("E1").Select
ActiveCell.FormulaR1C1 = _
"=CONCATENATE('WorksheetA'!RC[6],"" "",'WorksheetA'!RC[5])"
Range("E2").Select
Columns("E:E").EntireColumn.AutoFit
Range("F1").Select
ActiveCell.FormulaR1C1 = "=IF('WorksheetA'!RC[6]>0,'WorksheetA'!RC[6],"""")"
Range("A1").Select
Selection.AutoFill Destination:=Range("A1:A5000"), Type:=xlFillDefault
Range("A1:A5000").Select
Range("B1").Select
Selection.AutoFill Destination:=Range("B1:B5000"), Type:=xlFillDefault
Range("B1:B5000").Select
Range("C1").Select
Selection.AutoFill Destination:=Range("C1:C5000"), Type:=xlFillDefault
Range("C1:C5000").Select
Range("E1").Select
Selection.AutoFill Destination:=Range("E1:E5000"), Type:=xlFillDefault
Range("E1:E5000").Select
Range("F1").Select
Selection.AutoFill Destination:=Range("F1:F5000"), Type:=xlFillDefault
Range("F1:F5000").Select
End Sub