Trying to copy and paste grids not working

vbanovice123

Board Regular
Joined
Apr 15, 2011
Messages
91
I have used similar logic to copy and paste a range and it has worked. The only difference is that the below has the data in Grids, but I ensured that the cell size is the same.

Any help is appreciated.

This is the main file that calls another macro - File A

Private Sub CommandButton2_Click()
Call CopyTo13MHardCopy
End Sub

Sub CopyTo13MHardCopy()

Workbooks.Open Filename:= _
"F:\Focus\TestCopy\OnePagersTemplates_CopyPasteProject\OnePagers_Templates\OnePagersGrid_Template.xlsm"
Application.Run "OnePagersGrid_Template.xlsm!Sheet1.CopyToPrimeGridHardCopy"

End Sub


This is the called macro - File B

Sub CopyToPrimeGridHardCopy()
'copy_range_sheet_qtr(sheet, rngname)
copy_range_sheet_grid "Agency", "AgencyGrid"
copy_range_sheet_grid "RefiPlus", "RefiPlusGrid"
copy_range_sheet_grid "DU_Refi", "DU_RefiGrid"
copy_range_sheet_grid "NonHARP", "NonHARPGrid"
copy_range_sheet_grid "FHAVA", "FHAVAGrid"
copy_range_sheet_grid "FHA", "FHAGrid"
copy_range_sheet_grid "VA", "VAGrid"
copy_range_sheet_grid "Rural", "RuralGrid"
copy_range_sheet_grid "HFI", "HFIGrid"
copy_range_sheet_grid "AWM", "AWMGrid"

Application.ScreenUpdating = True
End Sub
Private Sub CommandButton2_Click()
Call CopyToPrimeGridHardCopy
End Sub


Private Sub CommandButton2_Click()
Call CopyToPrimeGridHardCopy
End Sub



This is the copy range function. I stepped through the code and it does not like the below:

Set rngDest = ActiveWorkbook.Sheets(sheet).Range("A1")


Public Sub copy_range_sheet_grid(sheet As String, rngname As String)
Dim rngCopy As Range
Dim rngDest As Range
On Error Resume Next
Set rngCopy = Sheets(sheet).Range(rngname)
On Error GoTo 0
' Make sure the range is valid
If rngCopy Is Nothing Then
MsgBox "Please select a worksheet range and try again.", vbExclamation, _
"No Range Selected"
Else
Application.ScreenUpdating = False
Workbooks.Open Filename:= _
"F:\Focus\TestCopy\OnePagersTemplates_CopyPasteProject\OnePagers_Templates\Prime_Grid_HardCopyV2.xlsx"
Set rngDest = ActiveWorkbook.Sheets(sheet).Range("A1")
'.Resize(rngCopy.Rows.Count, rngCopy.Columns.Count)
rngCopy.Copy
rngDest.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
rngDest.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
rngDest.PasteSpecial Paste:=xlPasteColumnWidths, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
ActiveWorkbook.Close SaveChanges:=True
Application.CutCopyMode = True 'Clear clipboard
Application.ScreenUpdating = True
End If

End Sub
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
I narrowed it down to where the problem is: What is wrong here?

rngDest.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
 
Upvote 0

Forum statistics

Threads
1,224,613
Messages
6,179,903
Members
452,948
Latest member
Dupuhini

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