I want to save my workbook with a filename depending on data in one of the cells. This isn't too difficult, but I want to use a three character code instead of the full cell contents in the original.
So if cell F2 contains "United States" then Dim = "USA"
Else if it contains "Great Britain" then "GBR"
Else if it contains "India" then "IND"
Else "JAP"
Then at the bottom:
Save as `Filename:="C:\My documents\"` & Dim from above & "File" &
Format(date, "yyyymmdd") & ". xlsx"
So the file name depends on a shortened version of the F2 cell's contents.
Sub BACS()
'
' BACS Macro
'
'
Windows("Book1").Activate
Sheets.Add After:=ActiveSheet
Sheets("Sheet1").Select
Columns("I:I").Select
Selection.Copy
Sheets("Sheet2").Select
Columns("A:A").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
Selection.NumberFormat = "000000"
Sheets("Sheet1").Select
Columns("H:H").Select
Selection.Copy
Sheets("Sheet2").Select
Columns("B:B").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
Selection.NumberFormat = "00000000"
Sheets("Sheet1").Select
Columns("L:L").Select
Selection.Copy
Sheets("Sheet2").Select
Columns("C:C").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Sheets("Sheet1").Select
Columns("N:N").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Sheet2").Select
Columns("D:D").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Sheets("Sheet1").Select
Columns("J:J").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Sheet2").Select
Columns("E:E").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
Selection.NumberFormat = "#,##0.00"
Rows("1:1").Select
Selection.Delete Shift:=xlUp
Cells.Select
Selection.Replace What:="/", Replacement:="", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Selection.Replace What:="&", Replacement:="", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Selection.Replace What:="(", Replacement:="", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Selection.Replace What:=")", Replacement:="", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Sheets("Sheet2").Select
Sheets("Sheet2").Move
ChDir "C:\Users\Desktop"
ActiveWorkbook.SaveAs Filename:= _
"C:\Users\Desktop\” &
IF Sheet1.Range(“F2”).Value = “United States” Then
Debug.Print “USA”
ElseIf Sheet1.Range(“F2”).Value = “Great Britain” Then
Debug.Print “GBR”
ElseIf Sheet1.Range(“F2”).Value = “India” Then
Debug.Print “IND”
Else
Debug.Print “JAP”
End If
& “ IMPORT BACS " & Format(Date, "yyyymmdd") & ".csv", FileFormat:= _
xlCSV, CreateBackup:=False
End Sub