VBA Macro to copy paste and create and save a new from from data file

ARIF0204

New Member
Joined
Mar 11, 2015
Messages
4
Hi all: I need help on the following:

Scenario:
I have a master database of information in Excel Called Data. It has a lot of fields. I have a form that I need to automatically filled with each row data from the master and then a save the form with a specific style (AgencyName_SiteAddress in a destination folder say C:\Forms) for each row of data.

I can create a macro to copy and paste information from various data cell to appropriate form fields, but I cannot seem to make excel save repeat the process for each row (loop process) and save each file separately. Need some help.

I know it may be seriously complicated for me but I know you guys can do it.

I need this program to make my life easy I have 4500 such rows that I need to manually create a form from (you can understand the frustration! :(:confused:)

Any help would be appreciated.

Since I cannot post the Excel file I am going to give you an example in one line below:[TABLE="class: cms_table, width: 500"]
<tbody>[TR]
[TD]Agency Name[/TD]
[TD]Agency Address[/TD]
[TD]Agency Number[/TD]
[TD]Site Address[/TD]
[TD]Site Number[/TD]
[TD]RowNumber[/TD]
[/TR]
[TR]
[TD]Agency 1[/TD]
[TD]1 Orange Street[/TD]
[TD]1001[/TD]
[TD]20 Banana Street[/TD]
[TD]5001[/TD]
[TD]1[/TD]
[/TR]
[TR]
[TD]Agency 2[/TD]
[TD]2 Orange St.[/TD]
[TD]1002[/TD]
[TD]5 Melon St.[/TD]
[TD]5002[/TD]
[TD]2[/TD]
[/TR]
</tbody>[/TABLE]

TabName: Data

The form I have is based on this information in another sheet called Form (TabeName:Form): It looks like below

Section 1:

Agency Name: (cell G3:Ab3)
Agency Address: (Cell G6:AB6)
Agency Number: (Cell C9:E9)

Section 2:

Agency Address: (Cell 613:AB13)
Agency Number: (Cell C13:13)


Thank you guys!


Arif
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
Sorry one correction to the Section 2 :

Site Address (instead of Agency): (Cell 613:AB13)
Site Number: (instead of Agency): (Cell C13:13)

Thanks.
 
Upvote 0
See if this works for you.

Code:
Sub Saver()
Dim i As Integer
Dim Temporary As Workbook
Dim CurrentWB As Workbook
Dim CurrentWS As Worksheet
Dim TempString As String

Set CurrentWB = ThisWorkbook
Set CurrentWS = ActiveSheet

    For i = 2 To 4500
        If Cells(i, 1).Value = "" Then
            Exit For
        End If
        
        Set Temporary = Workbooks.Add
        
        CurrentWB.Activate
        TempString = Cells(i, 1).Value & " " & Cells(i, 4).Value
        CurrentWS.Range(Cells(i, 1), Cells(i, 6)).Copy
        Temporary.Activate
        Range("A1").PasteSpecial xlPasteAll
        Temporary.SaveAs TempString & ".xlsx"
        Temporary.Close
    Next i

End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,231
Messages
6,170,884
Members
452,364
Latest member
springate

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