I have written a code which open a worksheet that contains a SQL data connection, I then refresh the data, copy the values and attempt to paste that information into the original spreadsheet.
the data does not paste, however, if i manually step through the code hitting F8 the data pastes - i can't figure out why this is -
if this is an easy question my apologies, I am new to VBA, I asked around my office and searched google - still can't find an answer - here is the code
Sub getdata() ' ' getdata Macro ' ' Keyboard Shortcut: Ctrl+a ' ' make holdings report tab visible and clear the contents
Sheets("Holdings Report").Visible = True
Sheets("Holdings Report").Activate
Range("A2:J65536").Select
Selection.ClearContents
' open the original holdings report, refresh data, copy data
Workbooks.Open "\\hcc-fileprint\sys\Share\Institutional Group\Rebalancing\HCNet Update.xlsm"
Sheets("Sheet1").Activate
Application.Wait Now + TimeValue("00:00:02")
ActiveWorkbook.RefreshAll
Application.Wait Now + TimeValue("00:00:02")
ActiveWorkbook.RefreshAll
Range("A2:J65536").Select
Selection.Copy
'activate the rebalancing spreadsheet paste the values and then hide the tab
ThisWorkbook.Activate
Sheets("Holdings Report").Activate
Range("A2").Select
ActiveSheet.paste
End Sub