Sub ExportOtherCharges()
Dim cel As Range
Dim R As Range
Dim LC As Range
Dim OutR As Range
Dim TWB As Workbook
Dim ExpWB As Workbook
Dim OCSht As Worksheet
Dim ExpSht As Worksheet
Dim FSA As Variant
Dim PathFile As String
Dim FileName As String
Dim Path As String
Dim v As Variant
Dim A As String
Set TWB = ThisWorkbook
Set OCSht = TWB.Sheets("Other Charges")
Set cel = OCSht.Range("A2")
Set R = OCSht.Range(cel, cel.End(xlDown))
For Each cel In R
If cel.Value <> "" Then
Set LC = cel
Else
Exit For
End If
Next cel
Set cel = OCSht.Range("A1")
Set R = OCSht.Range(cel, Intersect(LC.EntireRow, cel.End(xlToRight).EntireColumn))
FSA = Application.GetSaveAsFilename("Other Charges.xls", "Excel Files (*.xls), *.xls", , "Select a File Name for 'Other Charges'")
If FSA = False Then Exit Sub
PathFile = FSA
A = Dir(PathFile, vbNormal)
If A <> "" Then
FileName = GetFileName(PathFile)
v = MsgBox(FileName & " already exists. Do you want to overwrite it?", vbYesNoCancel)
If v <> vbYes Then Exit Sub
End If
Workbooks.Add
Set ExpWB = ActiveWorkbook
Set ExpSht = ExpWB.ActiveSheet
Set cel = ExpSht.Range("A1")
Set OutR = ExpSht.Range(cel, cel.Offset(R.Rows.Count - 1, R.Columns.Count - 1))
R.Copy
OutR.PasteSpecial (xlPasteValuesAndNumberFormats)
ExpSht.Name = "Other Charges"
OutR.EntireColumn.AutoFit
ExpSht.Range("A1").Select
On Error Resume Next
Application.DisplayAlerts = False
ExpWB.SaveAs PathFile, xlExcel8
ExpWB.Close savechanges:=False
Beep
Beep
Application.DisplayAlerts = True
On Error GoTo 0
Set TWB = Nothing
Set OCSht = Nothing
End Sub