PDA

View Full Version : Save a part of the sheet with a specific name



Yulyo
10-26-2017, 12:24 AM
Hello all,

I have a macro that saves me my excel workbook, in a specific location, with a name from a specific cell.

The problems i have right now are these:
- i don't want the macro to save me the entire workbook, only sheet1
- i don't want the macro to save the entire sheet 1, only A1:V100
- in cell X5 i have a date (25.10.2017) <---- this date will be the name of the saved file, but i need the macro to save the file with a name like this "171025"

This is the code i have right now:


Sub Save()
Dim Path As String
Dim filename As String
Path = "C:\Users\Computer\Desktop\1801-1901\"
filename = Range("X5")
ActiveWorkbook.SaveAs filename:=Path & filename & ".xls", FileFormat:=xlNormal
End Sub


Thank you!

offthelip
10-26-2017, 07:57 AM
try this:

Sub Savefile()Dim Path As String
Dim filename As String
Path = "C:\Users\Computer\Desktop\1801-1901\"


With Worksheets("Sheet1")


temp = .Cells(5, 24)
yr = Right(CStr(Year(temp)), 2)
mn = CStr(Month(temp))
dy = CStr(Day(temp))


filename = (dy & mn & yr)
inarr = Range(.Cells(1, 1), .Cells(100, 22))
End With
Workbooks.Add
With Worksheets("Sheet1")
Range(.Cells(1, 1), .Cells(100, 22)) = inarr
End With


ActiveWorkbook.SaveAs filename:=Path & filename & ".xls", FileFormat:=xlNormal
End Sub