copy and past data from specific cells from multiple workbooks to master workbook (but need to copy the cell even if it is empty)

okinawa

New Member
Joined
Sep 2, 2022
Messages
2
Office Version
  1. 2021
Platform
  1. Windows
  2. Mobile
Hello ,

i need to make the bellow code copy even blank cell (to avoid input data from 2 workbooks in the same row), because the final output is going to be storing the data from each workbook to a single row .

VBA Code:
Sub Copy_specific_Cells_From_other_workbooks_auto_RF()

Dim FileName$, sPath$
Dim wkbDest As Workbook, wkbSource As Workbook
Dim wsDest As Worksheet, wsSource As Worksheet

Application.ScreenUpdating = False

sPath = "D:\TSSRs\PO11\TSS Reports\WL TSSR\"
'sPath = "C:\Users\user\Documents\HP Laptop\Documents\Documents\Jobs\DIT\IDMB\Stack Overflow\okinawa\"

Set wkbDest = ThisWorkbook
'setting worksheet to improve readability
Set wsDest = wkbDest.Sheets("Master")

FileName = Dir(sPath)
Do While Len(FileName) > 0
    'open workbook for read only
    Set wkbSource = Workbooks.Open(sPath & FileName)
    'setting worksheet to improve readability
    Set wsSource = wkbSource.Sheets(2)
    
    wsSource.Range("B2").Copy
    wsDest.Cells(wsDest.Rows.Count, "I").End(xlUp).Offset(1, 0).PasteSpecial (xlPasteValues)
    wsSource.Range("B4").Copy
    wsDest.Cells(wsDest.Rows.Count, "J").End(xlUp).Offset(1, 0).PasteSpecial (xlPasteValues)
    wsSource.Range("B6").Copy
    wsDest.Cells(wsDest.Rows.Count, "K").End(xlUp).Offset(1, 0).PasteSpecial (xlPasteValues)
    wsSource.Range("B7").Copy
    wsDest.Cells(wsDest.Rows.Count, "L").End(xlUp).Offset(1, 0).PasteSpecial (xlPasteValues)
   
    'not needed since we're closing the workbook; so it will be done automatically
    
    'Application.CutCopyMode = False
    
    wkbSource.Close SaveChanges:=False
    
    FileName = Dir
Loop

Application.ScreenUpdating = True


End Sub

Please help and thanks in advance
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.

Forum statistics

Threads
1,223,268
Messages
6,171,100
Members
452,379
Latest member
IainTru

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