Import from different workbook

Nanogirl21

Active Member
Joined
Nov 19, 2013
Messages
330
Office Version
  1. 365
Platform
  1. Windows
Hi,

Happy New Year!

How can I import and replace data from another workbook into the active worksheet?

Ideally, I’d like a prompt to select the import file since it will be different every time I use the VBA. The sheet name in the import file will always be named Default.
The import data would be pasted in the active sheet of the workbook starting in row 2 (row 1 is headers). All “old” data should be removed.
A prompt confirming successful import would be helpful too.

Thank you for any help.
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
How about
VBA Code:
Sub Nanogirl()
   Dim Fname As Variant
   Dim Wbk As Workbook
   Dim Ws As Worksheet
   
   Set Ws = ActiveSheet
   Fname = Application.GetOpenFilename
   If Fname = "" Then Exit Sub
   Set Wbk = Workbooks.Open(Fname)
   Ws.UsedRange.Offset(1).Clear
   Wbk.Sheets("Default").UsedRange.Offset(1).Copy Ws.Range("A2")
End Sub
 
Upvote 0
How about
VBA Code:
Sub Nanogirl()
   Dim Fname As Variant
   Dim Wbk As Workbook
   Dim Ws As Worksheet
  
   Set Ws = ActiveSheet
   Fname = Application.GetOpenFilename
   If Fname = "" Then Exit Sub
   Set Wbk = Workbooks.Open(Fname)
   Ws.UsedRange.Offset(1).Clear
   Wbk.Sheets("Default").UsedRange.Offset(1).Copy Ws.Range("A2")
End Sub

This worked perfectly. Is there a way to close the import workbook after the task is complete?
 
Upvote 0
How about
VBA Code:
Sub Nanogirl()
   Dim Fname As Variant
   Dim Wbk As Workbook
   Dim Ws As Worksheet
   
   Set Ws = ActiveSheet
   Fname = Application.GetOpenFilename
   If Fname = "" Then Exit Sub
   Set Wbk = Workbooks.Open(Fname)
   Ws.UsedRange.Offset(1).Clear
   Wbk.Sheets("Default").UsedRange.Offset(1).Copy Ws.Range("A2")
   Wbk.Close False
End Sub
 
Upvote 0
Solution
How about
VBA Code:
Sub Nanogirl()
   Dim Fname As Variant
   Dim Wbk As Workbook
   Dim Ws As Worksheet
  
   Set Ws = ActiveSheet
   Fname = Application.GetOpenFilename
   If Fname = "" Then Exit Sub
   Set Wbk = Workbooks.Open(Fname)
   Ws.UsedRange.Offset(1).Clear
   Wbk.Sheets("Default").UsedRange.Offset(1).Copy Ws.Range("A2")
   Wbk.Close False
End Sub

Thank you so much. You are always a great help.
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,213,536
Messages
6,114,207
Members
448,554
Latest member
Gleisner2

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