vba to copy data from open workbook to a closed workbook

Deepas

New Member
Joined
Mar 2, 2021
Messages
12
Office Version
  1. 365
Platform
  1. Windows
hello i fairly new to VBA, request your help for the following.

i need to copy data from cells "m99 to m115" located in sheet1 of "stocks data" excel file and transpose it to the last empty row in sheet1 of "application list" excel file (closed workbook).
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
hello i fairly new to VBA, request your help for the following.

i need to copy data from cells "m99 to m115" located in sheet1 of "stocks data" excel file and transpose it to the last empty row in sheet1 of "application list" excel file (closed workbook).
can some one help me with code for the same? Thankyou in advance :)
 
Upvote 0
Try this. Just change the file path of your workbook to match your directory layout:
VBA Code:
Sub MyCopy()

    Dim srcWB As Workbook
    Dim dstWB As Workbook
    Dim nr As Long
   
    Application.ScreenUpdating = False
   
'   Capture current workbook as source workbook
    Set srcWB = ActiveWorkbook
   
'   Open other file
    Workbooks.Open "C:\Temp\Application List.xlsx"
   
'   Capture destination workbook
    Set dstWB = ActiveWorkbook
   
'   Find first available row
    nr = dstWB.Sheets("Sheet1").Cells(rows.Count, "A").End(xlUp).Row + 1
   
'   Copy data from source workbook
    srcWB.Activate
    Sheets("Stocks Data").Activate
    Range("M99:M115").Copy
    dstWB.Activate
    Sheets("Sheet1").Activate
    Range("A" & nr).PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
        False, Transpose:=True
    Application.CutCopyMode = False
   
'   Save workbook & close
    dstWB.Save
    dstWB.Close
   
    Application.ScreenUpdating = True
   
    MsgBox "Macro complete!"
   
End Sub
 
Upvote 0
Try this. Just change the file path of your workbook to match your directory layout:
VBA Code:
Sub MyCopy()

    Dim srcWB As Workbook
    Dim dstWB As Workbook
    Dim nr As Long
  
    Application.ScreenUpdating = False
  
'   Capture current workbook as source workbook
    Set srcWB = ActiveWorkbook
  
'   Open other file
    Workbooks.Open "C:\Temp\Application List.xlsx"
  
'   Capture destination workbook
    Set dstWB = ActiveWorkbook
  
'   Find first available row
    nr = dstWB.Sheets("Sheet1").Cells(rows.Count, "A").End(xlUp).Row + 1
  
'   Copy data from source workbook
    srcWB.Activate
    Sheets("Stocks Data").Activate
    Range("M99:M115").Copy
    dstWB.Activate
    Sheets("Sheet1").Activate
    Range("A" & nr).PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
        False, Transpose:=True
    Application.CutCopyMode = False
  
'   Save workbook & close
    dstWB.Save
    dstWB.Close
  
    Application.ScreenUpdating = True
  
    MsgBox "Macro complete!"
  
End Sub
Thankyou so much, but i have a dialog box that opens up, which asks if i need to update the external links. I need to manually click Update, and then continue.. how can we tune the macro to automatically select Update option when the dialog box opens up.
 
Upvote 0
Try this. Just change the file path of your workbook to match your directory layout:

Thankyou so much, but i have a dialog box that opens up, which asks if i need to update the external links. I need to manually click Update, and then continue.. how can we tune the macro to automatically select Update option when the dialog box opens up.
That is a whole different question that should be posted to a new thread.
 
Upvote 0

Forum statistics

Threads
1,215,056
Messages
6,122,907
Members
449,096
Latest member
dbomb1414

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