VBA paste value to last blank cell

hajiali

Well-known Member
Joined
Sep 8, 2018
Messages
624
Office Version
  1. 2016
Platform
  1. Windows
VBA Code:
Sub PullFinalBidData()
  Dim wb As Workbook, fullpath As String
  Dim wt As Worksheet
  Set wt = Sheets("RA Build")
  With application.FileDialog(msoFileDialogFilePicker)
    .AllowMultiSelect = False
    .Filters.Add "Excel Files", "*.xlsx", 1
    If .Show <> -1 Then Exit Sub
    fullpath = .SelectedItems.item(1)
    Set wb = Workbooks.Open(fullpath)
    wb.Sheets(1).Range("B2:H500").Copy ThisWorkbook.Sheets("RA Build").Range("IX5")
    wb.Close False
  End With
End Sub

With the above code I am able to paste the value of B2:H500 of the selected file into IX5. IX5 at first is always blank cell with new file. If I want to use this macro multiple times and for each file that i open it Copies B2:H500 of the select file onto the next blank cell in column IX how would I redo this code.

any help is greatly appreciated.
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
Hey Hajiali

I modified one line of your code to find the last row using on the RA Build Sheet and then paste 1 row down.

I have not tested it so please let me know if it works
VBA Code:
Sub PullFinalBidData()
  Dim wb As Workbook, fullpath As String
  Dim wt As Worksheet
  Set wt = Sheets("RA Build")
  With Application.FileDialog(msoFileDialogFilePicker)
    .AllowMultiSelect = False
    .Filters.Add "Excel Files", "*.xlsx", 1
    If .Show <> -1 Then Exit Sub
    fullpath = .SelectedItems.Item(1)
    Set wb = Workbooks.Open(fullpath)
    wb.Sheets(1).Range("B2:H500").Copy ThisWorkbook.Sheets("RA Build").Range("IX" & ThisWorkbook.Sheets("RA Build").Range("IX" & Rows.Count).End(xlUp).Row + 1)
    wb.Close False
  End With
End Sub


Cheers
Caleeco
 
Upvote 0

Forum statistics

Threads
1,214,646
Messages
6,120,717
Members
448,985
Latest member
chocbudda

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