Copy and Paste Between Workbooks with Dynamic Ranges

reberryjr

Well-known Member
Joined
Mar 16, 2017
Messages
714
Office Version
  1. 365
Platform
  1. Windows
I don't know why I'm struggling with this, but I am. I'm trying to paste the value of 1 cell from workbook A into the first empty cell of column B in workbook X all the way until the last cell in column Q of workbook X.

VBA Code:
Dim mLR, sLR, aLR As Long

Set m = ThisWorkbook
Set mA = m.Sheets("ALM_Data_Upload")

mLR = mA.Range("A" & Rows.Count).End(xlUp).Row

'Opens file picker and sets the chosen file as "s" for future coding reference.
With Application.FileDialog(3)
    .AllowMultiSelect = False
    If .Show Then
        fullpath = .SelectedItems.Item(1)
        Set s = Workbooks.Open(fullpath)
    End If

    'Exits the sub if no file is chosen.
    If s Is Nothing Then Exit Sub
    
    Set sS = s.Worksheets(1)
    
    sLR = sS.Range("L" & Rows.Count).End(xlUp).Row
    
    'Copies the Step Number, Description and Expectation from the actual script and pastes it into the ALM Upload tab.
    sS.Range("A11:C11" & sLR).Copy
        mA.Range("L" & Rows.Count).End(xlUp).Offset(1, 0).PasteSpecial xlPasteValues
        
    aLR = sS.Range("L" & Rows.Count).End(xlUp).Row
    
    'Copies the Test Name from the actual script and pastes it into the ALM Upload tab.
    sS.Range("B1").Copy
       mA.range("B" & sLR+1  ":B" & aLR).pastespecial xlpastevalues
        'mA.Range("B" & Rows.Count).End(xlUp).Offset(1, 0).PasteSpecial xlPasteValues
 

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,908
Messages
6,175,304
Members
452,633
Latest member
DougMo

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