Error 1004 Method "Range" of object global failed

GarethG

New Member
Joined
Sep 9, 2019
Messages
10
Hi All,

I have one spreadsheet set up with a form detailed within the sheet using VBA and name manager to print data onto the form and save as a pdf. However I took the sheet and created a new one for a different purpose changing the form and all of the names in name manager to match the data I wanted in each section of the form but now when I press the print button within the sheet or save selected I get the error code 1004 Method "Range" of object global failed with the range name highlighted in yellow. How can I fix this error to make the sheet work?

[FONT=Verdana,Arial,Tahoma,Calibri,Geneva,sans-serif]Sub Printselected()[/FONT]
[FONT=Verdana,Arial,Tahoma,Calibri,Geneva,sans-serif]'set up your merge form by naming the merge fields _
with the same name as the data fields you are importing.



Dim wsForm As Worksheet, wsData As Worksheet
Dim sRngName As String, r As Long, c As Integer
Dim selected As String
selected = InputBox("Enter Ref number", "Print Single Sheet")
Set wsForm = Worksheets("Form") 'change to your sheet name of the form
Set wsData = Worksheets("2019") 'change to your sheet name with Data in
With wsData.Cells(1, 1).CurrentRegion
For r = 2 To .Rows.Count[/FONT]
[FONT=Verdana,Arial,Tahoma,Calibri,Geneva,sans-serif]
If Not wsData.Cells(r, 1).EntireRow.Hidden Then
For c = 1 To .Columns.Count
sRngName = wsData.Cells(1, c).Value
Range(RangeName(sRngName)).Value = wsData.Cells(r, c)
Next
If wsForm.Cells(2, 2) = selected Then
selected = 0
wsForm.PrintOut
Exit Sub
End If




[/FONT]
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
Does this RangeName(sRngName) evaluate to a valid named range?
Hi, the range name refers to the first cell A1 in the spreadsheet NC Evidence but not sure what I should call the range name as the form on the second tab is set up with a button to print selected and another for save selected whereby you type in the non conformance number and it saves or prints the relevant form by taking the data from the spreadsheet which ive set up the form using name manager with each title matching the titles of the data sheet
 
Upvote 0
I presume RangeName is a function that does something to sRngName. What does it do?
 
Upvote 0

Forum statistics

Threads
1,224,817
Messages
6,181,148
Members
453,021
Latest member
Justyna P

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