Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 82
Default Need help with named ranges in VBA

Hi,

I have a spreadsheet which lists all of our personnel and their vacation
days (manually entered). I've set up dynamic named ranges for each person in
order to query their vacation days and see if they are available for duty on
a particular day. The names are defined in the spreadsheet, not in VBA.

I'm trying to use a string variable to call the correct range and look for
the date in question to see if the individual will be on vacation the day his
name comes up on the rotation (in which case he will be substituted). I'm
getting Error 1004 Application or Object Defined Error on my With statement
in the code below.

How do I refer to a named range in VBA, using a find function?

'stName is a variable, determined by who is up for duty next.
'dtDate is the duty day. If this day shows up in the dynamic range that is
defined
'by the person's name, then blAvail is TRUE,
'meaning he is available for duty that day



With Worksheets("Vacation Days").Range(stName)
Set c = .Find(dtDate)
If c Is Nothing Then
blAvail = True
End If
End With

--
HTH

JonR
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,290
Default Need help with named ranges in VBA

Two examples that might help...

'JimsRng is a name defined in the spreadsheet.

'Assign the named range name to a String variable.
Sub nnn()
Dim stName As String
stName = Worksheets(2).Range("JimsRng").Name.Name
Worksheets(2).Range(stName).Select 'or Find...
End Sub

'Use the named range directly in the code.
Sub mmm()
Worksheets(2).Range("JimsRng").Select 'or Find...
End Sub
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware


"JonR"
wrote in message
Hi,
I have a spreadsheet which lists all of our personnel and their vacation
days (manually entered). I've set up dynamic named ranges for each person in
order to query their vacation days and see if they are available for duty on
a particular day. The names are defined in the spreadsheet, not in VBA.

I'm trying to use a string variable to call the correct range and look for
the date in question to see if the individual will be on vacation the day his
name comes up on the rotation (in which case he will be substituted). I'm
getting Error 1004 Application or Object Defined Error on my With statement
in the code below.

How do I refer to a named range in VBA, using a find function?

'stName is a variable, determined by who is up for duty next.
'dtDate is the duty day. If this day shows up in the dynamic range that is
defined
'by the person's name, then blAvail is TRUE,
'meaning he is available for duty that day

With Worksheets("Vacation Days").Range(stName)
Set c = .Find(dtDate)
If c Is Nothing Then
blAvail = True
End If
End With
--
HTH
JonR
  #3   Report Post  
Posted to microsoft.public.excel.programming
JMB JMB is offline
external usenet poster
 
Posts: 2,062
Default Need help with named ranges in VBA

You are sure the dynamic named range reference is correct? Your code snippet
works perfectly on my machine, but I will get the error you describe if I try
to reference a range name that does not exist.

Step throught the macro and, in the immediate window (after stName is
initialized), type
?Worksheets("Vacation Days").Range(stName).Address(True, True, xlA1, True)

and verify the dynamic named range address is correct.


"JonR" wrote:

Hi,

I have a spreadsheet which lists all of our personnel and their vacation
days (manually entered). I've set up dynamic named ranges for each person in
order to query their vacation days and see if they are available for duty on
a particular day. The names are defined in the spreadsheet, not in VBA.

I'm trying to use a string variable to call the correct range and look for
the date in question to see if the individual will be on vacation the day his
name comes up on the rotation (in which case he will be substituted). I'm
getting Error 1004 Application or Object Defined Error on my With statement
in the code below.

How do I refer to a named range in VBA, using a find function?

'stName is a variable, determined by who is up for duty next.
'dtDate is the duty day. If this day shows up in the dynamic range that is
defined
'by the person's name, then blAvail is TRUE,
'meaning he is available for duty that day



With Worksheets("Vacation Days").Range(stName)
Set c = .Find(dtDate)
If c Is Nothing Then
blAvail = True
End If
End With

--
HTH

JonR

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 82
Default Need help with named ranges in VBA

Thanks for the code guys, it was a big help. Found out it was a really
stupid error -- I had defined a named range, but there was nothing in it. No
wonder I'm getting errors! Duh!!
--


JonR



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Named ranges SheriTingle Excel Discussion (Misc queries) 2 February 14th 07 06:00 PM
Copy data in named ranges to a newer version of the same template to identical ranges handstand Excel Programming 0 August 21st 06 03:51 PM
Named ranges [email protected] Excel Discussion (Misc queries) 1 March 21st 06 10:33 PM
Like 123, allow named ranges, and print named ranges WP Excel Discussion (Misc queries) 1 April 8th 05 06:07 PM
named ranges - changing ranges with month selected gr8guy Excel Programming 2 May 28th 04 04:50 AM


All times are GMT +1. The time now is 06:44 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"