vb help

steve2115

Board Regular
Joined
Mar 17, 2014
Messages
82
Need help modifying the below code to add any new files imported to the bottom of my master sheet (Ariba Invoices). Currently when I import a new file it overwrites. I need it to find the last row on Ariba Invoices master sheet and add the new data.

Any help greatly appreciated.

Code:
Sub Button1_Click()
Dim OpenFileName As String
 Dim wb As Workbook
 'Select and Open workbook
 OpenFileName = Application.GetOpenFilename("Ariba Invoices,*.csv")
 If OpenFileName = "False" Then Exit Sub
 Set wb = Workbooks.Open(OpenFileName)
 'Get data EXAMPLE
 ThisWorkbook.Sheets("Ariba Invoices").Range("A:T").Value = wb.Sheets(1).Range("A:T").Value
 MsgBox ("Import Complete")
wb.Close
      
End Sub
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
Untested, but try
Code:
Sub Button1_Click()
   Dim OpenFileName As String
   Dim wb As Workbook
   Dim Rng As Range
   
   'Select and Open workbook
   OpenFileName = Application.GetOpenFilename("Ariba Invoices,*.csv")
   If OpenFileName = "False" Then Exit Sub
   Set wb = Workbooks.Open(OpenFileName)
   'Get data EXAMPLE
   Set Rng = wb.Sheets(1).UsedRange
   ThisWorkbook.Sheets("Ariba Invoices").Range("A" & Rows.Count).End(xlUp).Offset(1).Resize(Rng.Rows, Rng.Columns).Value = Rng.Value
   MsgBox ("Import Complete")
   wb.Close
        
End Sub
 
Upvote 0
Thanks for the quick reply. Just tested and received the following

Run-time error '1004':
Application-defined or object defined error

When debugging it's pointing to

Code:
[ ThisWorkbook.Sheets("Ariba Invoices").Range("A" & Rows.Count).End(xlUp).Offset(1).Resize(Rng.Rows, Rng.Columns).Value = Rng.Value/CODE]
 
Upvote 0
That line should be
Code:
   ThisWorkbook.Sheets("Ariba Invoices").Range("A" & Rows.Count).End(xlUp).Offset(1).Resize(Rng.Rows.Count, Rng.Columns.Count).Value = Rng.Value
 
Upvote 0
Glad to help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,286
Members
452,631
Latest member
a_potato

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