PC Review


Reply
Thread Tools Rate Thread

ask user to select a target sheet as an input for a macro

 
 
Yossi evenzur
Guest
Posts: n/a
 
      17th Jan 2008
How or what is the vba syntax if i want the user to select a atrget sheet for
a macro as an input?
 
Reply With Quote
 
 
 
 
Rick Rothstein \(MVP - VB\)
Guest
Posts: n/a
 
      17th Jan 2008
What about having your user kick off the macro from the sheet he/she wants
it to operate on? Then you can use ActiveSheet inside your macro to
reference it.

Rick


"Yossi evenzur" <(E-Mail Removed)> wrote in message
news:7BCFFE5F-AD1B-421A-BBD3-(E-Mail Removed)...
> How or what is the vba syntax if i want the user to select a atrget
> sheet for a macro as an input?


 
Reply With Quote
 
Rick Rothstein \(MVP - VB\)
Guest
Posts: n/a
 
      17th Jan 2008
Another possibility... Execute this statement in your macro at the point you
want to get the sheet name...

Answer = InputBox("Tell me a sheet name")

and then reference that sheet in your code using this Worksheets(Answer). As
an example...

Worksheets(Answer).Range("D4").Value = "Hello"

You will probably need to put some error checking code in just in case your
user types the sheet name in wrong though.

Rick


"Yossi evenzur" <(E-Mail Removed)> wrote in message
news:7BCFFE5F-AD1B-421A-BBD3-(E-Mail Removed)...
> How or what is the vba syntax if i want the user to select a atrget
> sheet for a macro as an input?


 
Reply With Quote
 
Yossi evenzur
Guest
Posts: n/a
 
      17th Jan 2008
Hi
It dosen't matter, the problem is that both the target and source sheets
have different names each time. in general i want to open an excel workbook
with two sheets (different names each time and no i need these names to stay
as they are) in the first sheet i add row and vlookup at the second sheet.
any better ideas?

"Rick Rothstein (MVP - VB)" wrote:

> What about having your user kick off the macro from the sheet he/she wants
> it to operate on? Then you can use ActiveSheet inside your macro to
> reference it.
>
> Rick
>
>
> "Yossi evenzur" <(E-Mail Removed)> wrote in message
> news:7BCFFE5F-AD1B-421A-BBD3-(E-Mail Removed)...
> > How or what is the vba syntax if i want the user to select a atrget
> > sheet for a macro as an input?

>
>

 
Reply With Quote
 
Yossi evenzur
Guest
Posts: n/a
 
      17th Jan 2008
Hi Rick
Please take a look at the following:
1)
Answer = InputBox("Tell me a sheet name")

'the Answer is"XXXX"

ActiveCell.FormulaR1C1 = _
"=VLOOKUP(R[1]C,'"What do I put HERE ???"'!R2C1:R255C3,3,FALSE)"

2) why can't i simply (simply?) click on the sheet?

"Rick Rothstein (MVP - VB)" wrote:

> Another possibility... Execute this statement in your macro at the point you
> want to get the sheet name...
>
> Answer = InputBox("Tell me a sheet name")
>
> and then reference that sheet in your code using this Worksheets(Answer). As
> an example...
>
> Worksheets(Answer).Range("D4").Value = "Hello"
>
> You will probably need to put some error checking code in just in case your
> user types the sheet name in wrong though.
>
> Rick
>
>
> "Yossi evenzur" <(E-Mail Removed)> wrote in message
> news:7BCFFE5F-AD1B-421A-BBD3-(E-Mail Removed)...
> > How or what is the vba syntax if i want the user to select a atrget
> > sheet for a macro as an input?

>
>

 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      17th Jan 2008
Dim wks as worksheet

set wks = nothing
on error resume next
set wks = application.inputbox _
(Prompt:="please click on a cell in the worksheet to use", type:=8).parent
on error resume next

if wks is nothing then
'user hit cancel, what should happen
else
msgbox wks.name
end if

You may want to consider creating a userform that displays the worksheet names
(in comboboxes??) and allow the user to select the sheet from that list.

If you want to try, take a look at the userform in Myrna Larson and Bill
Manville's compare program:

http://www.cpearson.com/excel/whatsnew.htm
look for compare.xla

Yossi evenzur wrote:
>
> How or what is the vba syntax if i want the user to select a atrget sheet for
> a macro as an input?


--

Dave Peterson
 
Reply With Quote
 
Rick Rothstein \(MVP - VB\)
Guest
Posts: n/a
 
      17th Jan 2008
1) You would use this formula...

ActiveCell.FormulaR1C1 = "=VLOOKUP(R[1]C," & Answer &
"!R2C1:R255C3,3,FALSE)"

2) If you had them click on the sheet tab, then that sheet would be selected
and you would have the situation I mentioned in my previous reply, only
delayed slightly... ActiveSheet would tell you what sheet they were on. Here
is another thought... if you know they will have to change sheets to make
your macro work (that is, the look up data is never going to be on the page
they are on when the macro is launched, then perhaps you could make use of
the Workbook's SheetActivate event to get recognize the new sheet had been
selected and get the sheet name from its Sh argument?

Rick


"Yossi evenzur" <(E-Mail Removed)> wrote in message
news:B4B84C93-5DFA-4535-8531-(E-Mail Removed)...
> Hi Rick
> Please take a look at the following:
> 1)
> Answer = InputBox("Tell me a sheet name")
>
> 'the Answer is"XXXX"
>
> ActiveCell.FormulaR1C1 = _
> "=VLOOKUP(R[1]C,'"What do I put HERE ???"'!R2C1:R255C3,3,FALSE)"
>
> 2) why can't i simply (simply?) click on the sheet?
>
> "Rick Rothstein (MVP - VB)" wrote:
>
>> Another possibility... Execute this statement in your macro at the point
>> you
>> want to get the sheet name...
>>
>> Answer = InputBox("Tell me a sheet name")
>>
>> and then reference that sheet in your code using this Worksheets(Answer).
>> As
>> an example...
>>
>> Worksheets(Answer).Range("D4").Value = "Hello"
>>
>> You will probably need to put some error checking code in just in case
>> your
>> user types the sheet name in wrong though.
>>
>> Rick
>>
>>
>> "Yossi evenzur" <(E-Mail Removed)> wrote in message
>> news:7BCFFE5F-AD1B-421A-BBD3-(E-Mail Removed)...
>> > How or what is the vba syntax if i want the user to select a atrget
>> > sheet for a macro as an input?

>>
>>


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
selecting target sheet as an input Yossi evenzur Microsoft Excel Programming 0 23rd Jan 2008 01:11 AM
Macro with input box to Select a column on active sheet Marcusdmc Microsoft Excel Programming 6 25th Sep 2007 07:53 PM
Changing target sheet name wihtin a macro =?Utf-8?B?SmltIEc=?= Microsoft Excel Misc 2 30th Jan 2006 03:05 AM
Help with Macro. -- User input for sheet name =?Utf-8?B?TWljaGFlbCBB?= Microsoft Excel Programming 9 6th Jan 2006 03:17 PM
CODE to select range based on User Input or Value of Input Field Sandi Gauthier Microsoft Excel Programming 4 8th Dec 2003 03:22 PM


Features
 

Advertising
 

Newsgroups
 


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