VBA: How to assign value of named range cell to external file?

cfp999

New Member
Joined
Jun 23, 2009
Messages
8
Hi,

I am trying to transfer data to an external file from a worksheet using VBA: current date, username and a global range named cell "Score". Date and username is succesfully transfered to column A and B in the first empty row. "Score" however gives me an error. I don't know how to refer to it. It's working globally in my worksheet.

Code:
Dim emptyRow As Long

'Find first empty row in open file

emptyRow = WorksheetFunction.CountA(.Range("A:A")) + 1
   
'Transfer data to column A, B & C
        
        .Cells(emptyRow, 1).Value = Format(Now(), "mm/dd/yyyy")
        .Cells(emptyRow, 2).Value = Environ("UserName")
        .Cells(emptyRow, 3).Value = [Score].Value

So far I have tried to use = Range("Score") instead of [Score].Value, but it's not working either. Any ideas?
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
if it is a named range - you have to refer to the name.
If it's scope is the Workbook, then the way to refer to it is:
Code:
Workbooks("yourworkbooknamehere").names("Score").value
or
ThisWorkbook.names("Score").value
 
Upvote 0

Forum statistics

Threads
1,223,229
Messages
6,170,881
Members
452,364
Latest member
springate

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