Modify where existing VBA pastes

vmpage

Board Regular
Joined
Mar 6, 2014
Messages
53
Good morning.

I need some help altering existing VBA. Right now, the code will paste under the last used row. I would like to modify this so that the copied data is pasted starting at B5 of the master, with each file pasting underneath.

What I currently have is this:
Code:
'set to the current active workbook (the 'Master')
    Set wbThis = ActiveWorkbook
    Set sht1 = wbThis.Sheets("Master")


'Clear out old content
    sht1.Range("B5:C34").ClearContents


Folder = "U:\Ships - Export Controlled Documents\Hopper\Hopper 8C1\PMO\_Daily PODs\Daily Updates"
Fname = Dir(Folder)


While (Fname <> "")


  Set wbTarget = Workbooks.Open(Filename:=Folder & Fname)


  vDB = wbTarget.Sheets(1).Range("A2:B9")


  sht1.Range("b" & Rows.Count).End(xlUp)(2).Resize(UBound(vDB, 1), UBound(vDB, 2)) = vDB


 Fname = Dir


 'close the Daily POD file
  wbTarget.Close
 Wend
How can I modify the paste line to start at B5 of the master, then paste at the next blank for each file that is looped through?

Thank you all for the help!
 
Last edited by a moderator:

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
Where is it pasting the data?
 
Upvote 0
Try
Code:
Sht1.Range("b5:B34").SpecialCells(xlBlanks)(1).Resize(UBound(Vdb, 1), UBound(Vdb, 2)) = Vdb
This assumes that there will always be blank spaces.
 
Upvote 0
Try
Code:
Sht1.Range("b5:B34").SpecialCells(xlBlanks)(1).Resize(UBound(Vdb, 1), UBound(Vdb, 2)) = Vdb
This assumes that there will always be blank spaces.

Sorry for the late response, and thank you for the info

I get an error on that line that reads:
Run-time error '1004':

Unable to get the SpecialCells property of the Range class

I have no idea what that means!
 
Upvote 0
How many files are you copying from?
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,184
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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