Hi all,
I am trying to get a macro for an extremely repetitive task to copy a row onto another sheet, save the workbook as column A + space + D + Space + B then go onto the next row and so on.
1. Copy row 2 from "Paste" sheet (Data is from column A to AN)
2. Paste onto row 2 on another sheet called "Template"
3. Then save the whole workbook (not just the sheet) as macro enabled and name it column A + space + D + Space + B
4. Then it can refilter to the next row...
What I have so far is missing 1 & 2 and then doesn't save the whole workbook and names it column A only. Help!
I am trying to get a macro for an extremely repetitive task to copy a row onto another sheet, save the workbook as column A + space + D + Space + B then go onto the next row and so on.
1. Copy row 2 from "Paste" sheet (Data is from column A to AN)
2. Paste onto row 2 on another sheet called "Template"
3. Then save the whole workbook (not just the sheet) as macro enabled and name it column A + space + D + Space + B
4. Then it can refilter to the next row...
What I have so far is missing 1 & 2 and then doesn't save the whole workbook and names it column A only. Help!
VBA Code:
Dim sh As Worksheet, lr As Long, rng As Range, eRng As Range, c As Range, wb As Workbook
Set sh = Sheets("Paste") 'Edit sheet name
lr = sh.Cells(Rows.Count, 1).End(xlUp).Row
Set rng = sh.Range("A2:A" & lr)
sh.Columns("AP").Insert
rng.AdvancedFilter xlFilterCopy, , sh.Range("AP2"), Unique:=True
Set eRng = sh.Range("AP2", sh.Cells(Rows.Count, 42).End(xlUp))
For Each c In eRng
Set wb = Workbooks.Add
sh.Range("A1:AN1").Copy wb.Sheets(1).Range("A1")
sh.Range("A2:A" & lr).AutoFilter 1, c.Value
rng.SpecialCells(xlCellTypeVisible).EntireRow.Copy wb.Sheets(1).Cells(Rows.Count, 1).End(xlUp)(2)
wb.SaveAs ThisWorkbook.Path & "\" & c.Value
sh.AutoFilterMode = False
wb.Close False
Set wb = Nothing
Next
sh.Columns("AP").Delete
End Sub