I have two macro that I would like to combine them into one
The first Macro select a range of data based on the value in column J
The second saves the entire worksheet as a csv file.
I want only to save the selected data as csv. can this be done?
Thank You
Sub SelectByCellValue()
'UpdatebyExtendoffice20161128
Dim lastrow As Long
Dim xRg As Range, yRg As Range
'change Sheet1 to suit
With ThisWorkbook.Worksheets("UPLOAD")
lastrow = .Cells(.Rows.Count, "J").End(xlUp).Row
Application.ScreenUpdating = False
For Each xRg In .Range("J1:C" & lastrow)
If UCase(xRg.Text) = "FALSE" Then
If yRg Is Nothing Then
Set yRg = .Range("A" & xRg.Row).Resize(, 5)
Else
Set yRg = Union(yRg, .Range("A" & xRg.Row).Resize(, 5))
End If
End If
Next xRg
Application.ScreenUpdating = True
End With
If Not yRg Is Nothing Then yRg.Select
End Sub
Sub CopyToCSV()
Dim MyPath As String
Dim MyFileName As String
'The path and file names:
MyPath = "C:\Temp"
MyFileName = "Journal" & Format(Date, "ddmmyyhhmmss")
'Makes sure the path name ends with "\":
If Not Right(MyPath, 1) = "\" Then MyPath = MyPath & "\"
'Makes sure the filename ends with ".csv"
If Not Right(MyFileName, 4) = ".csv" Then MyFileName = MyFileName & ".csv"
'Copies the sheet to a new workbook:
Sheets("Upload").Copy
'The new workbook becomes Activeworkbook:
With ActiveWorkbook
'Saves the new workbook to given folder / filename:
.SaveAs Filename:= _
MyPath & MyFileName, _
FileFormat:=xlCSV, _
CreateBackup:=False
'Closes the file
.Close False
End With
End Sub
Bookmarks