Hello guys.
I have, thanks to searching and asking for your kind suggestions, managed to build a VBA-macro to copy a range of data and create a CSV-file in a specific path.
All fine and dandy this far.
Can I modify my macro to instead specify the first row of valid data (Row 12) and then make the macro find the end of the selection automatically? IE. Last row with data in it.
Existing macro:
Private Sub Create_CSV()
Dim content As String
Dim Rng As Range
Set Rng = Range("A12:AS30")
Dim Path As String
Dim FileName1 As String
Dim FileName2 As String
Dim FileName3 As String
Dim sWB As Workbook, _
sWS As Worksheet
Dim dWB As Workbook, _
dWS As Worksheet
Path = "\\PATH\"
FileName1 = Range("A16")
FileName2 = Range("B16")
Set sWB = ActiveWorkbook
Set sWS = sWB.ActiveSheet
Set dWB = Workbooks.Add
Set dWS = dWB.Sheets(1)
sWS.Range("A12:AS30").Copy
dWS.Range("A1").PasteSpecial xlPasteValues
dWS.Range("A1").PasteSpecial xlPasteFormats
dWB.SaveAs filename:=Path & FileName1 & "_" & FileName2 & ".csv", FileFormat:=xlCSV, Local:=True, CreateBackup:=False
dWB.Close False
End Sub
I have, thanks to searching and asking for your kind suggestions, managed to build a VBA-macro to copy a range of data and create a CSV-file in a specific path.
All fine and dandy this far.
Can I modify my macro to instead specify the first row of valid data (Row 12) and then make the macro find the end of the selection automatically? IE. Last row with data in it.
Existing macro:
Private Sub Create_CSV()
Dim content As String
Dim Rng As Range
Set Rng = Range("A12:AS30")
Dim Path As String
Dim FileName1 As String
Dim FileName2 As String
Dim FileName3 As String
Dim sWB As Workbook, _
sWS As Worksheet
Dim dWB As Workbook, _
dWS As Worksheet
Path = "\\PATH\"
FileName1 = Range("A16")
FileName2 = Range("B16")
Set sWB = ActiveWorkbook
Set sWS = sWB.ActiveSheet
Set dWB = Workbooks.Add
Set dWS = dWB.Sheets(1)
sWS.Range("A12:AS30").Copy
dWS.Range("A1").PasteSpecial xlPasteValues
dWS.Range("A1").PasteSpecial xlPasteFormats
dWB.SaveAs filename:=Path & FileName1 & "_" & FileName2 & ".csv", FileFormat:=xlCSV, Local:=True, CreateBackup:=False
dWB.Close False
End Sub