#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Inputbox

Hi All,

I am using Excels inputbox in VBA to obtain a cell
reference. See the following

Dim Rng as range
set rng = application.inputbox(Prompt:=prompt...Type:=8)
rng.select

Say rng was C8

What I want to do is to select C8 on each sheet using a
for each statement.

When I try it always slects C8 in sheet1 where the user
originally selected the rng. How can I generalise this so
it selects rng on the activesheet.

Thanks for your help.

Regards

Sadik
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Inputbox

Dim Rng as range
Dim sh as Worksheet
On error resume Next
set rng = application.inputbox(Prompt:=prompt...Type:=8)
On Error goto 0
If not rng is Nothing then
for each sh in Worksheets
sh.Activate
range(rng.address).Select
Next
End if


--
Regards,
Tom Ogilvy

"sadik" wrote in message
...
Hi All,

I am using Excels inputbox in VBA to obtain a cell
reference. See the following

Dim Rng as range
set rng = application.inputbox(Prompt:=prompt...Type:=8)
rng.select

Say rng was C8

What I want to do is to select C8 on each sheet using a
for each statement.

When I try it always slects C8 in sheet1 where the user
originally selected the rng. How can I generalise this so
it selects rng on the activesheet.

Thanks for your help.

Regards

Sadik



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default Inputbox

One way:

To select "rng on the activesheet":

Dim rng As Range
On Error Resume Next 'in case user clicks Cancel
Set rng = Application.InputBox(Prompt:="prompt:", Type:=8)
On Error GoTo 0
If Not rng Is Nothing Then _
ActiveSheet.Range(rng.Address).Select

Not sure how that squares with your wanting "to select C8 on each sheet
using a for each statement", which would be more like:

Dim wkSht As Worksheet
Dim rng As Range
On Error Resume Next 'in case user clicks Cancel
Set rng = Application.InputBox(Prompt:="prompt:", Type:=8)
On Error GoTo 0
If Not rng Is Nothing Then
For Each wkSht In Worksheets
wkSht.Range(rng.Address).Select
'do something, presumably
Next wkSht
End If



In article ,
"sadik" wrote:

Hi All,

I am using Excels inputbox in VBA to obtain a cell
reference. See the following

Dim Rng as range
set rng = application.inputbox(Prompt:=prompt...Type:=8)
rng.select

Say rng was C8

What I want to do is to select C8 on each sheet using a
for each statement.

When I try it always slects C8 in sheet1 where the user
originally selected the rng. How can I generalise this so
it selects rng on the activesheet.

Thanks for your help.

Regards

Sadik

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default Inputbox

Oops, forgot to edit: in the second function, substitute

With wkSht.Range(rng.Address)
'do something, presumably
End With

For

wkSht.Range(rng.Address).Select



In article ,
JE McGimpsey wrote:

One way:

To select "rng on the activesheet":

Dim rng As Range
On Error Resume Next 'in case user clicks Cancel
Set rng = Application.InputBox(Prompt:="prompt:", Type:=8)
On Error GoTo 0
If Not rng Is Nothing Then _
ActiveSheet.Range(rng.Address).Select

Not sure how that squares with your wanting "to select C8 on each sheet
using a for each statement", which would be more like:

Dim wkSht As Worksheet
Dim rng As Range
On Error Resume Next 'in case user clicks Cancel
Set rng = Application.InputBox(Prompt:="prompt:", Type:=8)
On Error GoTo 0
If Not rng Is Nothing Then
For Each wkSht In Worksheets
wkSht.Range(rng.Address).Select
'do something, presumably
Next wkSht
End If

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
InputBox Help Mark[_8_] Excel Discussion (Misc queries) 2 November 24th 08 11:07 PM
InputBox with VBA Mark[_8_] Excel Discussion (Misc queries) 0 November 24th 08 12:39 AM
InputBox peyman Excel Discussion (Misc queries) 4 September 28th 07 04:53 PM
InputBox GeorgeJ Excel Discussion (Misc queries) 5 July 12th 07 01:20 AM
inputbox Lawson Excel Programming 2 October 7th 03 08:58 PM


All times are GMT +1. The time now is 11:52 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"