Using Named Range in VBA

ManUBlueJay

Active Member
Joined
Aug 30, 2012
Messages
302
Office Version
  1. 2016
Platform
  1. Windows
I have a named Range called "MyRange" that is not associated to a cell but is a calculation counting how many rows are used.
I would like to have a message box at the end of my code to tell me how many records were effected.

I did the following but it returns a Run Time Error 1004 on "LineCount = Range("MyRange").Value" line

VBA Code:
Sub MyMacro()

Dim LineCount As String
LineCount = Range("MyRange").Value

Range("Import_DataBaseRange") = Range("Import_UpdateRange").Value

MsgBox ((LineCount) & " Records Have Been Added")
ActiveWorkbook.Save
End Sub
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
How about
VBA Code:
linecount = [MyRange]
 
Upvote 0
I have already tried that without success. I have never managed if my named range is not associated to a cell. I am sure there is a simple way
 
Upvote 0
What is the formula you are using in the name?
 
Upvote 0
Perfect
Thank you
Would that work for other applications like Range ("A1")= Evaluate("MyRange")
 
Upvote 0
What happens if you try?
 
Upvote 0
Stunning!! That was not just "fluff". Thank you for providing with a little bit of further education
 
Upvote 0

Forum statistics

Threads
1,215,039
Messages
6,122,799
Members
449,095
Latest member
m_smith_solihull

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