Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Goto Worksheet with Defined Range Name

I have a macro that defines a range name as follows:

Set rngCopyTo = Application.InputBox( _
prompt:="Select the UPPER LEFT CELL of the " _
& "range to which you wish to paste", _
Title:="Copy Range Formulae", Type:=8).Cells(1, 1)

I do not know in advance the worksheet that will ultimately contain the
range for "rngCopyTo".

Later in the macro, I want to goto "rngCopyTo".

I have tried the following, but I get an error message unless the selected
worksheet contains the range for "rngCopyTo". Is there a VBA code that will
find and select the worksheet that contains "rngCopyTo"?

rngCopyTo.Select

Thank you for any help.

--
needVBAhelp
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Goto Worksheet with Defined Range Name

The VBA help show how to use the GOTO method
This example selects cell A154 on Sheet1 and then scrolls through the
worksheet to display the range.

Application.Goto Reference:=Worksheets("Sheet1").Range("A154"), _
scroll:=True

You can replace the range with a named range
Sub test()
Application.Goto Reference:=Application.Range("rngCopyTo"), _
scroll:=True
End Sub


"needVBAhelp" wrote:

I have a macro that defines a range name as follows:

Set rngCopyTo = Application.InputBox( _
prompt:="Select the UPPER LEFT CELL of the " _
& "range to which you wish to paste", _
Title:="Copy Range Formulae", Type:=8).Cells(1, 1)

I do not know in advance the worksheet that will ultimately contain the
range for "rngCopyTo".

Later in the macro, I want to goto "rngCopyTo".

I have tried the following, but I get an error message unless the selected
worksheet contains the range for "rngCopyTo". Is there a VBA code that will
find and select the worksheet that contains "rngCopyTo"?

rngCopyTo.Select

Thank you for any help.

--
needVBAhelp

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Goto Worksheet with Defined Range Name

Thank you, Joel. I tried:

Application.Goto Reference:=Application.Range("rngCopyTo"), _
scroll:=True


But I got the following error message:

Method 'Range' of object '_Application' failed

Any suggestions? Thanks again.

--
needVBAhelp


"Joel" wrote:

The VBA help show how to use the GOTO method
This example selects cell A154 on Sheet1 and then scrolls through the
worksheet to display the range.

Application.Goto Reference:=Worksheets("Sheet1").Range("A154"), _
scroll:=True

You can replace the range with a named range
Sub test()
Application.Goto Reference:=Application.Range("rngCopyTo"), _
scroll:=True
End Sub


"needVBAhelp" wrote:

I have a macro that defines a range name as follows:

Set rngCopyTo = Application.InputBox( _
prompt:="Select the UPPER LEFT CELL of the " _
& "range to which you wish to paste", _
Title:="Copy Range Formulae", Type:=8).Cells(1, 1)

I do not know in advance the worksheet that will ultimately contain the
range for "rngCopyTo".

Later in the macro, I want to goto "rngCopyTo".

I have tried the following, but I get an error message unless the selected
worksheet contains the range for "rngCopyTo". Is there a VBA code that will
find and select the worksheet that contains "rngCopyTo"?

rngCopyTo.Select

Thank you for any help.

--
needVBAhelp

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Goto Worksheet with Defined Range Name

You will get your error if the name range doesn't exist on you worksheet.
Make sure you have a named range called rngCopyTo. The names range doesn't
needed quotes.

"needVBAhelp" wrote:

Thank you, Joel. I tried:

Application.Goto Reference:=Application.Range("rngCopyTo"), _
scroll:=True


But I got the following error message:

Method 'Range' of object '_Application' failed

Any suggestions? Thanks again.

--
needVBAhelp


"Joel" wrote:

The VBA help show how to use the GOTO method
This example selects cell A154 on Sheet1 and then scrolls through the
worksheet to display the range.

Application.Goto Reference:=Worksheets("Sheet1").Range("A154"), _
scroll:=True

You can replace the range with a named range
Sub test()
Application.Goto Reference:=Application.Range("rngCopyTo"), _
scroll:=True
End Sub


"needVBAhelp" wrote:

I have a macro that defines a range name as follows:

Set rngCopyTo = Application.InputBox( _
prompt:="Select the UPPER LEFT CELL of the " _
& "range to which you wish to paste", _
Title:="Copy Range Formulae", Type:=8).Cells(1, 1)

I do not know in advance the worksheet that will ultimately contain the
range for "rngCopyTo".

Later in the macro, I want to goto "rngCopyTo".

I have tried the following, but I get an error message unless the selected
worksheet contains the range for "rngCopyTo". Is there a VBA code that will
find and select the worksheet that contains "rngCopyTo"?

rngCopyTo.Select

Thank you for any help.

--
needVBAhelp

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Goto Worksheet with Defined Range Name

Joel,

The problem is when my macro is run, I do not know which worksheet will
contain the range name. I am trying to goto the worksheet that happens to
contain the range name. Is this possible?

Thanks one more time.

--
needVBAhelp


"Joel" wrote:

You will get your error if the name range doesn't exist on you worksheet.
Make sure you have a named range called rngCopyTo. The names range doesn't
needed quotes.

"needVBAhelp" wrote:

Thank you, Joel. I tried:

Application.Goto Reference:=Application.Range("rngCopyTo"), _
scroll:=True


But I got the following error message:

Method 'Range' of object '_Application' failed

Any suggestions? Thanks again.

--
needVBAhelp


"Joel" wrote:

The VBA help show how to use the GOTO method
This example selects cell A154 on Sheet1 and then scrolls through the
worksheet to display the range.

Application.Goto Reference:=Worksheets("Sheet1").Range("A154"), _
scroll:=True

You can replace the range with a named range
Sub test()
Application.Goto Reference:=Application.Range("rngCopyTo"), _
scroll:=True
End Sub


"needVBAhelp" wrote:

I have a macro that defines a range name as follows:

Set rngCopyTo = Application.InputBox( _
prompt:="Select the UPPER LEFT CELL of the " _
& "range to which you wish to paste", _
Title:="Copy Range Formulae", Type:=8).Cells(1, 1)

I do not know in advance the worksheet that will ultimately contain the
range for "rngCopyTo".

Later in the macro, I want to goto "rngCopyTo".

I have tried the following, but I get an error message unless the selected
worksheet contains the range for "rngCopyTo". Is there a VBA code that will
find and select the worksheet that contains "rngCopyTo"?

rngCopyTo.Select

Thank you for any help.

--
needVBAhelp



  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default Goto Worksheet with Defined Range Name

I think you might neet two InputBox variables to accomplish what you want to
do.
Psuedo code:
cpytoWks = InputBox("Enter Destination Worksheet Name". "Worksheet")
rngCopyTo = Application.InputBox( _
prompt:="Select the UPPER LEFT CELL of the " _
& "range to which you wish to paste", _
Title:="Copy Range Formulae", Type:=8).Cells(1, 1)
Wks1.Range("A1:C5").Copy Sheets(cpytoWks).Range(rngCopyTo)

That gets you to the sheet and range without a GoTo.
"needVBAhelp" wrote:

I have a macro that defines a range name as follows:

Set rngCopyTo = Application.InputBox( _
prompt:="Select the UPPER LEFT CELL of the " _
& "range to which you wish to paste", _
Title:="Copy Range Formulae", Type:=8).Cells(1, 1)

I do not know in advance the worksheet that will ultimately contain the
range for "rngCopyTo".

Later in the macro, I want to goto "rngCopyTo".

I have tried the following, but I get an error message unless the selected
worksheet contains the range for "rngCopyTo". Is there a VBA code that will
find and select the worksheet that contains "rngCopyTo"?

rngCopyTo.Select

Thank you for any help.

--
needVBAhelp

  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Goto Worksheet with Defined Range Name

Yes, this works. I did not want to have to manually enter the worksheet name,
but that looks like the solution.

Thanks much for your help.
--
needVBAhelp


"JLGWhiz" wrote:

I think you might neet two InputBox variables to accomplish what you want to
do.
Psuedo code:
cpytoWks = InputBox("Enter Destination Worksheet Name". "Worksheet")
rngCopyTo = Application.InputBox( _
prompt:="Select the UPPER LEFT CELL of the " _
& "range to which you wish to paste", _
Title:="Copy Range Formulae", Type:=8).Cells(1, 1)
Wks1.Range("A1:C5").Copy Sheets(cpytoWks).Range(rngCopyTo)

That gets you to the sheet and range without a GoTo.
"needVBAhelp" wrote:

I have a macro that defines a range name as follows:

Set rngCopyTo = Application.InputBox( _
prompt:="Select the UPPER LEFT CELL of the " _
& "range to which you wish to paste", _
Title:="Copy Range Formulae", Type:=8).Cells(1, 1)

I do not know in advance the worksheet that will ultimately contain the
range for "rngCopyTo".

Later in the macro, I want to goto "rngCopyTo".

I have tried the following, but I get an error message unless the selected
worksheet contains the range for "rngCopyTo". Is there a VBA code that will
find and select the worksheet that contains "rngCopyTo"?

rngCopyTo.Select

Thank you for any help.

--
needVBAhelp

  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Goto Worksheet with Defined Range Name

Your RngCopyTo isn't a name of a range (except by coincidence)--it's just an
object/range variable.

Option Explicit
Sub testme01()

Dim RngCopyTo As Range

Set RngCopyTo = Nothing
On Error Resume Next
Set RngCopyTo = Application.InputBox( _
prompt:="Select the UPPER LEFT CELL of the " _
& "range to which you wish to paste", _
Title:="Copy Range Formulae", Type:=8).Cells(1, 1)
On Error GoTo 0

If RngCopyTo Is Nothing Then
'user hit cancel--or did you do that earlier in the code???
Else
Application.Goto RngCopyTo, scroll:=True
End If

End Sub

needVBAhelp wrote:

I have a macro that defines a range name as follows:

Set rngCopyTo = Application.InputBox( _
prompt:="Select the UPPER LEFT CELL of the " _
& "range to which you wish to paste", _
Title:="Copy Range Formulae", Type:=8).Cells(1, 1)

I do not know in advance the worksheet that will ultimately contain the
range for "rngCopyTo".

Later in the macro, I want to goto "rngCopyTo".

I have tried the following, but I get an error message unless the selected
worksheet contains the range for "rngCopyTo". Is there a VBA code that will
find and select the worksheet that contains "rngCopyTo"?

rngCopyTo.Select

Thank you for any help.

--
needVBAhelp


--

Dave Peterson
  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Goto Worksheet with Defined Range Name

The best way to write VBA code is to use names ranges on worksheets which you
can manual enter under the worksheet menu Insert - Name - Define. As you add
and delete cells on your worksheets the named ranges will change the same way
formula do when the worksheet is modified. Names include both sheet names
and ranges of cells.

The code I gave you uses the named range rngCopyTo. You can change the
range of cells at any time and the VBA code will not have to be modified.



"needVBAhelp" wrote:

Yes, this works. I did not want to have to manually enter the worksheet name,
but that looks like the solution.

Thanks much for your help.
--
needVBAhelp


"JLGWhiz" wrote:

I think you might neet two InputBox variables to accomplish what you want to
do.
Psuedo code:
cpytoWks = InputBox("Enter Destination Worksheet Name". "Worksheet")
rngCopyTo = Application.InputBox( _
prompt:="Select the UPPER LEFT CELL of the " _
& "range to which you wish to paste", _
Title:="Copy Range Formulae", Type:=8).Cells(1, 1)
Wks1.Range("A1:C5").Copy Sheets(cpytoWks).Range(rngCopyTo)

That gets you to the sheet and range without a GoTo.
"needVBAhelp" wrote:

I have a macro that defines a range name as follows:

Set rngCopyTo = Application.InputBox( _
prompt:="Select the UPPER LEFT CELL of the " _
& "range to which you wish to paste", _
Title:="Copy Range Formulae", Type:=8).Cells(1, 1)

I do not know in advance the worksheet that will ultimately contain the
range for "rngCopyTo".

Later in the macro, I want to goto "rngCopyTo".

I have tried the following, but I get an error message unless the selected
worksheet contains the range for "rngCopyTo". Is there a VBA code that will
find and select the worksheet that contains "rngCopyTo"?

rngCopyTo.Select

Thank you for any help.

--
needVBAhelp



  #11   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Goto Worksheet with Defined Range Name

Don & Dave,

Each of your suggestions worked great. Thanks much.
Thanks to Joel as well for staying with me through this.
--
needVBAhelp


"Dave Peterson" wrote:

Your RngCopyTo isn't a name of a range (except by coincidence)--it's just an
object/range variable.

Option Explicit
Sub testme01()

Dim RngCopyTo As Range

Set RngCopyTo = Nothing
On Error Resume Next
Set RngCopyTo = Application.InputBox( _
prompt:="Select the UPPER LEFT CELL of the " _
& "range to which you wish to paste", _
Title:="Copy Range Formulae", Type:=8).Cells(1, 1)
On Error GoTo 0

If RngCopyTo Is Nothing Then
'user hit cancel--or did you do that earlier in the code???
Else
Application.Goto RngCopyTo, scroll:=True
End If

End Sub

needVBAhelp wrote:

I have a macro that defines a range name as follows:

Set rngCopyTo = Application.InputBox( _
prompt:="Select the UPPER LEFT CELL of the " _
& "range to which you wish to paste", _
Title:="Copy Range Formulae", Type:=8).Cells(1, 1)

I do not know in advance the worksheet that will ultimately contain the
range for "rngCopyTo".

Later in the macro, I want to goto "rngCopyTo".

I have tried the following, but I get an error message unless the selected
worksheet contains the range for "rngCopyTo". Is there a VBA code that will
find and select the worksheet that contains "rngCopyTo"?

rngCopyTo.Select

Thank you for any help.

--
needVBAhelp


--

Dave Peterson

  #12   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Goto Worksheet with Defined Range Name

I would have guessed that Don's code would only work if there was a range named
rngtocopy--not a range variable with that name.

needVBAhelp wrote:

Don & Dave,

Each of your suggestions worked great. Thanks much.
Thanks to Joel as well for staying with me through this.
--
needVBAhelp

"Dave Peterson" wrote:

Your RngCopyTo isn't a name of a range (except by coincidence)--it's just an
object/range variable.

Option Explicit
Sub testme01()

Dim RngCopyTo As Range

Set RngCopyTo = Nothing
On Error Resume Next
Set RngCopyTo = Application.InputBox( _
prompt:="Select the UPPER LEFT CELL of the " _
& "range to which you wish to paste", _
Title:="Copy Range Formulae", Type:=8).Cells(1, 1)
On Error GoTo 0

If RngCopyTo Is Nothing Then
'user hit cancel--or did you do that earlier in the code???
Else
Application.Goto RngCopyTo, scroll:=True
End If

End Sub

needVBAhelp wrote:

I have a macro that defines a range name as follows:

Set rngCopyTo = Application.InputBox( _
prompt:="Select the UPPER LEFT CELL of the " _
& "range to which you wish to paste", _
Title:="Copy Range Formulae", Type:=8).Cells(1, 1)

I do not know in advance the worksheet that will ultimately contain the
range for "rngCopyTo".

Later in the macro, I want to goto "rngCopyTo".

I have tried the following, but I get an error message unless the selected
worksheet contains the range for "rngCopyTo". Is there a VBA code that will
find and select the worksheet that contains "rngCopyTo"?

rngCopyTo.Select

Thank you for any help.

--
needVBAhelp


--

Dave Peterson


--

Dave Peterson
  #13   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Goto Worksheet with Defined Range Name

Dave,

You are correct. I did set rngtocopy as a range name within the VBA code.
--
needVBAhelp


"Dave Peterson" wrote:

I would have guessed that Don's code would only work if there was a range named
rngtocopy--not a range variable with that name.

needVBAhelp wrote:

Don & Dave,

Each of your suggestions worked great. Thanks much.
Thanks to Joel as well for staying with me through this.
--
needVBAhelp

"Dave Peterson" wrote:

Your RngCopyTo isn't a name of a range (except by coincidence)--it's just an
object/range variable.

Option Explicit
Sub testme01()

Dim RngCopyTo As Range

Set RngCopyTo = Nothing
On Error Resume Next
Set RngCopyTo = Application.InputBox( _
prompt:="Select the UPPER LEFT CELL of the " _
& "range to which you wish to paste", _
Title:="Copy Range Formulae", Type:=8).Cells(1, 1)
On Error GoTo 0

If RngCopyTo Is Nothing Then
'user hit cancel--or did you do that earlier in the code???
Else
Application.Goto RngCopyTo, scroll:=True
End If

End Sub

needVBAhelp wrote:

I have a macro that defines a range name as follows:

Set rngCopyTo = Application.InputBox( _
prompt:="Select the UPPER LEFT CELL of the " _
& "range to which you wish to paste", _
Title:="Copy Range Formulae", Type:=8).Cells(1, 1)

I do not know in advance the worksheet that will ultimately contain the
range for "rngCopyTo".

Later in the macro, I want to goto "rngCopyTo".

I have tried the following, but I get an error message unless the selected
worksheet contains the range for "rngCopyTo". Is there a VBA code that will
find and select the worksheet that contains "rngCopyTo"?

rngCopyTo.Select

Thank you for any help.

--
needVBAhelp

--

Dave Peterson


--

Dave Peterson

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
Application-defined or object-defined error (worksheet, range, sel darxoul Excel Programming 4 August 2nd 06 01:59 PM
Copying A Range of Cells From one Sheet to Another - Error Application Defined or Object Defined Matt[_39_] Excel Programming 3 July 25th 06 01:13 AM
Find defined Name in List, then Goto ufo_pilot Excel Programming 2 December 22nd 05 12:28 PM
Using a data validation list to look up a defined named range in another worksheet Laura Hunt Charts and Charting in Excel 0 November 24th 05 02:29 PM
Range - Application Defined or Object Defined Error Dyl Excel Programming 6 October 31st 05 07:57 PM


All times are GMT +1. The time now is 11:22 AM.

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"