LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Searching for a specific cell using a variable.


hmm...
actually "Range("Sheet2!A"&1).Value" works for me (so it's probably
already correct) whether you're using it to read or write the value....
so the error must be in how you reference your textbox.
what error message are you getting?
are you using a textbox in a userform? if you are and the code below is
located somewhere NOT in the user form, then you have to reference the
textbox through its userform.

YourUserForm.TextBox1.Text = Range("Sheet2!A"&1).Value

try this...
1. Create a userform (name it MyUserForm) and put a textbox (name it
MyTextBox) and a button (name it MyButton). (Be sure to set ShowModal
property of MyUserForm to True - though it is set to True by default.)
2. Add an OnClick event handler to MyButton; MyUserForm should be
hidden (NOT UNLOADED) when MyButton is clicked:

Private Sub MyButton_Click()
'Just HIDE MyUserForm; don't unload
Me.Hide 'To hide MyUserForm

'Experiment: Comment line of code above and uncomment below
'Unload Me
End Sub

3. Add a button to any sheet in your workbook. Don't use Sheet2 if
you're going to reference/use [Range("Sheet2!A"&1).Value].
4. When you create the button in the sheet, the 'Assign Macro' dialog
box should appear. Create a new macro for the button by clicking 'New'.
This should take you to the VBA Editor, insided a subroutine (the
OnClick event handler for the button - named something like
Button1_Click).
5. Add code to the subroutine so it should look something like:

Sub Button1_Click()
MyUserForm.MyTextBox.Text = Range("Sheet2!A" & 1).Value
MyUserForm.Show
Range("Sheet2!A" & 1).Value = MyUserForm.MyTextBox.Text
End Sub

6. Set the text in cell A1 in Sheet2 to any text you like.
7. Save (or don't save) your work...

When you click on the button in the sheet, MyUserForm should appear.
Notice the text in MyTextBox is the same as with the text in cell A1 in
Sheet2.
When you change the text in MyTextBox and click MyButton, the value in
cell A1 in Sheet2 should be equal to the text you typed in MyTextBox.
But, when you click the Close control button (the 'X' button) in
MyUserForm, cell A1 in Sheet2 should now be empty. This is because
MyUserForm has been unloaded.

I know... the demo above is already a bit way-off...
But, I hope it gave you some ideas... :)

One more thing, if you're only concerned with referencing a cell value
through a textbox, try using the 'ControlSource' property of the text
box...

If the demo doesn't work, contact me...

SystemHack Wrote:
I tried all 3 methods below and get errors on each one. All I am trying
to do is when I click on the button, move the information from A,1 on
Sheet 2 to the TextBox on Sheet 1. Any ideas what I am doing wrong ?

TextBox1.Text = Range(Sheet2!A&1).Value
TextBox1.Text = Range(Sheet2!A,1).Value
TextBox1.Text = Range("Sheet2!A"&1).Value

Now that I try it, I can't even get this to work on the same worksheet.



--
T-®ex
------------------------------------------------------------------------
T-®ex's Profile: http://www.excelforum.com/member.php...o&userid=26572
View this thread: http://www.excelforum.com/showthread...hreadid=398944

 
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
Searching for specific text - how to spacia Excel Worksheet Functions 0 May 13th 08 09:39 PM
Searching in 'variable' worksheets FicsiPapa Excel Discussion (Misc queries) 1 March 15th 08 10:51 AM
searching for specific text clerk Excel Discussion (Misc queries) 1 December 7th 05 12:16 AM
Searching for a variable field danw Excel Programming 1 July 5th 05 10:56 PM
Searching for specific text simoncohen[_5_] Excel Programming 3 July 12th 04 05:47 PM


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