Copying cells from one workbook to another and saving an individual file for each cell

Andyg666

New Member
Joined
Apr 24, 2024
Messages
12
Office Version
  1. 365
Platform
  1. Windows
Hi,
I am new to macros but hope you can help me.
I have a list of items and related information (model, serial number etc) and I need a macro so that I can press a button and export the item name and serial number of each item into another workbook for each item on the original list including a pop up option of where these new workbooks would be saved.

I hope this makes sense, please help
 
Make sure that the file already contains a sheet named "Certificate" which of course contains a certificate with no data from row 8 down. This macro will start by asking you to select a save folder for the file. If the save folder will always be the same, it can be hard coded so you don't have to select it each time. Please advise.
VBA Code:
Sub CreateFiles()
    Application.ScreenUpdating = False
    Dim sPath As String, srcWS As Worksheet, lCol As Long, item As Range
    Set srcWS = Sheet1
    lCol = srcWS.Cells(3, Columns.Count).End(xlToLeft).Column
    With Application.FileDialog(msoFileDialogFolderPicker)
        .Title = "Please select a save folder for this file (" & ActiveSheet.Name & ")."
        .AllowMultiSelect = False
        .Show
        If .SelectedItems.Count > 0 Then
            sPath = .SelectedItems(1)
        End If
    End With
    For Each item In srcWS.Range("A4", srcWS.Range("A" & Rows.Count).End(xlUp))
        Sheets("Certificate").Copy
        With ActiveSheet
            .Name = srcWS.Range("A4")
            .Range("B5") = srcWS.Range("B1")
            .Range("B6") = srcWS.Range("A4")
            .Range("B7") = srcWS.Range("B4")
            .Range("A9").Resize(lCol - 2) = WorksheetFunction.Transpose(srcWS.Range("C4").Resize(, lCol - 2))
        End With
        ActiveWorkbook.SaveAs Filename:=sPath & Application.PathSeparator & ActiveSheet.Name & "-" & item & ".xlsx", FileFormat:=51
        ActiveWorkbook.Close False
    Next item
    Application.ScreenUpdating = True
End Sub
 
Upvote 0

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)

Forum statistics

Threads
1,215,446
Messages
6,124,900
Members
449,194
Latest member
JayEggleton

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top