Chirag R Raval
Member
Dear Sir,
I want to create selection as named range to process & reference on that named range
below code not work properly.
Error Shown On below line
'ActiveWorkbook.Names.add Name:=myrng, RefersTo:=selection"
Which Error Displayed?
Run Time error 1004
Application defined or Object defined error
may be ..I read somewhere (& also bear, suffered, faced trouble in macros as per below)
if I declare selection as range type variable , then that's you generate fault in VBA due to there are VBA rule that you can not use word "Selection" in your sub-function name or "Selection" could not be expression because "selection" keyword used by VBA it self , you can not use it that way..
I also & already used this statement selection.name="myrng" (as myrng variable type "String")
but it also fails & displayed
Run Time Error "91"
"Object Variable or "With Block Variable" & also various type of errors faced..
is there are matter of declare variable?
which become name & which become range object?
is there are must necessary to declare 2 variables, as 1 for name and other for range?
if there are something need to "set" keyword to use?
or there are need to must be "set" this range as object?
Is there are must be require fully qualified reference for work this code?
how to resolve? how can I create named range from selection (selection by code-not manually) & work on that named range or some process on that named range.
hope there are some rock solid solution to declare without fail selection of named range & how to successfully work on or reference that named range differently in your further process.
Regards,
Chirag Raval
I want to create selection as named range to process & reference on that named range
below code not work properly.
Code:
Dim myRangeName As String 'Store Name of Range Name
Dim myrng as range 'for Store range object
'specify defined name
range(ActiveCell, ActiveCell.End(xlDown)).Select
selection.Resize(, 4).Select
myRangeName = "myrng"
'create named range with workbook scope. Defined name is as specified. Cell range is the selection
ActiveWorkbook.Names.add Name:=myrng, RefersTo:=selection
range("myrng").Border
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With 'Selection No end
' End With 'active sheet no end
Error Shown On below line
'ActiveWorkbook.Names.add Name:=myrng, RefersTo:=selection"
Which Error Displayed?
Run Time error 1004
Application defined or Object defined error
may be ..I read somewhere (& also bear, suffered, faced trouble in macros as per below)
if I declare selection as range type variable , then that's you generate fault in VBA due to there are VBA rule that you can not use word "Selection" in your sub-function name or "Selection" could not be expression because "selection" keyword used by VBA it self , you can not use it that way..
I also & already used this statement selection.name="myrng" (as myrng variable type "String")
but it also fails & displayed
Run Time Error "91"
"Object Variable or "With Block Variable" & also various type of errors faced..
is there are matter of declare variable?
which become name & which become range object?
is there are must necessary to declare 2 variables, as 1 for name and other for range?
if there are something need to "set" keyword to use?
or there are need to must be "set" this range as object?
Is there are must be require fully qualified reference for work this code?
how to resolve? how can I create named range from selection (selection by code-not manually) & work on that named range or some process on that named range.
hope there are some rock solid solution to declare without fail selection of named range & how to successfully work on or reference that named range differently in your further process.
Regards,
Chirag Raval
Last edited: