How to Link Contents from an Excel worksheet to another Excel workbook using VBA?

nia_m

New Member
Joined
Aug 31, 2018
Messages
1
I have built VBA code that links cell contents from one Excel sheet <code style="font-style: inherit; font-variant: inherit; font-weight: inherit; margin: 0px; padding: 1px 5px; border: 0px; font-stretch: inherit; line-height: inherit; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; vertical-align: baseline; box-sizing: inherit; background-color: rgb(239, 240, 241); white-space: pre-wrap;">Employee Form</code> to another worksheet <code style="font-style: inherit; font-variant: inherit; font-weight: inherit; margin: 0px; padding: 1px 5px; border: 0px; font-stretch: inherit; line-height: inherit; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; vertical-align: baseline; box-sizing: inherit; background-color: rgb(239, 240, 241); white-space: pre-wrap;">Employee Database</code> in the same workbook as below:


HTML:
Sub Submit_Form() 
    Dim LastRow AsLong, ws As Worksheet
    Set ws = Sheets("Employee Database") 
    LastRow = ws.Range("A"& Rows.Count).End(xlUp).Row +1 

    ws.Range("A"& LastRow).Value = Worksheets("Employee Form").Range("D7").Value
    ....
    ws.Range("Z"& LastRow).Value = Worksheets("Employee Form").Range("AB").Value
EndSub

The code works well, but how to modify the code now that these sheets are in separate Excel files? The new Excel files are the same as the respective names of these worksheets.
Thanks!

 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.

Forum statistics

Threads
1,223,909
Messages
6,175,312
Members
452,634
Latest member
cpostell

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