Search code examples
vbaexcelexcel-2013

Excel Macro read cell values


I am looking to put together a program simply

It reads a line in excel A1:E1

If A1 has a value it moves to B1 if B1 has a value it moves to C1 etc.

Then it stops on the last cell with a value.

Then it saves the file based on the cell value.

I ended up with this code.

Sub NamePDF()
    Dim fp As String
    Dim wb As Workbook

    fp = "C:\Users\mdowney\Desktop\TestFolder\" & Cells(1, Columns.Count).End(xlToLeft)
    Set wb = ActiveWorkbook

    wb.ExportAsFixedFormat Type:=xlTypePDF, Filename:=fp, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False
End Sub

Solution

  • try something like

    activeworkbook.saveas "C:\temp\" & cells(1,columns.count).end(xltoleft) & ".xlsx"
    

    This will not save the macros with the workbook though.