Import data and paste it after the last row

jeremiah_j2k

New Member
Joined
Oct 16, 2014
Messages
32
Hello,

Need some advise and your expertise to modify my macro so it will add the imported data after the last entry on my existing table. currently, the code copy and paste the data to row 2 of the Database sheet but I am keeping records to that table would just like to update it instead of overwriting the data that i have. Can you advise how to make the macro add the imported data to the last row of the Database sheet? Thanks in advance for your help.


VBA Code:
Sub Import_RAW()
    Application.ScreenUpdating = False
    'Selection.AutoFilter
    With Application.FileDialog(msoFileDialogFilePicker)
        .AllowMultiSelect = False
        .ButtonName = "Import"
        .Filters.Clear
        '.Filters.Add "Excel Files", "*.csv"
        '.Filters.Add "CSV File", "*.xlsx"
        .Title = "Ticket Rating"
        .Show
        If .SelectedItems.Count Then
            strFileSelected = .SelectedItems(1)
        Else
            'MsgBox "Cancelled by user!"
            Exit Sub 'Ideally, should exit from the bottom of the sub-routine.
        End If
    End With
    'Worksheets("Database").Range("A2:q10000").ClearContents
    Range("AD1").Value = VBA.FileDateTime(strFileSelected) '& " +8 GMT"
 
    fncFileSelected = strFileSelected

    With Workbooks.Open(Filename:=fncFileSelected, ReadOnly:=True)
        .Sheets(1).Cells(1).End(xlToRight).Offset(, 2).Resize(, 17).Value = ThisWorkbook.Worksheets("Database").Range("A1:q1").Value
        .Sheets(1).Cells(1).CurrentRegion.AdvancedFilter Action:=xlFilterCopy, CopyToRange:=.Sheets(1).Cells(1).End(xlToRight).Offset(, 2).CurrentRegion, Unique:=False
        With .Sheets(1).Cells(1).End(xlToRight).Offset(, 2).CurrentRegion
            ThisWorkbook.Worksheets("Database").Range("A1:q1").Resize(.Rows.Count, .Columns.Count).Value = .Value
        ActiveWorkbook.RefreshAll
        End With
        Workbooks(.Name).Close 0
        ActiveWorkbook.RefreshAll
   
       
    End With

End Sub
 

Attachments

  • 2022-05-21 11_26_11-TestForm_Save - Excel.png
    2022-05-21 11_26_11-TestForm_Save - Excel.png
    51.5 KB · Views: 16

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.

Forum statistics

Threads
1,215,650
Messages
6,126,016
Members
449,280
Latest member
Miahr

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