Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 57
Default Range problem

I am currently writing an application that involves selecting a different
worksheet based on the choice made by the user. Here is my code so far. The
problem is with the set emp_range line. I keep on getting an "An application
defined or Object defined error" message. I pretty much copied the range code
from another application. (Changing certain things of course.)
What's wrong here?
Thanks,
David

Sub test3()
Dim str As String

str = Worksheets("Commands").Cells(2, 4)

Dim emp_range As Range
Set emp_range = Worksheets(str).Range("a1", Range("a2").End(xlDown))

For Each c In emp_range
MsgBox c.Value
Next c

End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,120
Default Range problem

It works fine if this line

str = Worksheets("Commands").Cells(2, 4)

returns a valid worksheet name in the activeworkbook

--
HTH

Bob Phillips

"David Gerstman" wrote in message
...
I am currently writing an application that involves selecting a different
worksheet based on the choice made by the user. Here is my code so far.

The
problem is with the set emp_range line. I keep on getting an "An

application
defined or Object defined error" message. I pretty much copied the range

code
from another application. (Changing certain things of course.)
What's wrong here?
Thanks,
David

Sub test3()
Dim str As String

str = Worksheets("Commands").Cells(2, 4)

Dim emp_range As Range
Set emp_range = Worksheets(str).Range("a1", Range("a2").End(xlDown))

For Each c In emp_range
MsgBox c.Value
Next c

End Sub



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 318
Default Range problem

Use the following

Sub test3()
Dim str As String
Dim c As Range

str = Worksheets("Commands").Cells(2, 4)

Dim emp_range As Range
With Worksheets(str)
Set emp_range = .Range(.Range("a1"), .Range("a2").End(xlDown))

For Each c In emp_range
MsgBox c.Value
Next c
End With

End Sub


"David Gerstman" wrote:

I am currently writing an application that involves selecting a different
worksheet based on the choice made by the user. Here is my code so far. The
problem is with the set emp_range line. I keep on getting an "An application
defined or Object defined error" message. I pretty much copied the range code
from another application. (Changing certain things of course.)
What's wrong here?
Thanks,
David

Sub test3()
Dim str As String

str = Worksheets("Commands").Cells(2, 4)

Dim emp_range As Range
Set emp_range = Worksheets(str).Range("a1", Range("a2").End(xlDown))

For Each c In emp_range
MsgBox c.Value
Next c

End Sub

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
3D range problem br549 Excel Worksheet Functions 1 June 15th 07 08:52 PM
Problem with range [email protected] Excel Discussion (Misc queries) 7 February 14th 07 04:06 PM
Range Problem jesmin Excel Discussion (Misc queries) 19 December 19th 05 12:11 AM
Used Range Problem Charles Williams Excel Programming 0 August 4th 03 08:30 AM
Used Range Problem Donald Lloyd Excel Programming 6 August 3rd 03 10:18 PM


All times are GMT +1. The time now is 07:02 PM.

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

About Us

"It's about Microsoft Excel"