Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to place a cell value into a userform?

Status
Not open for further replies.

bsurfn99

Technical User
Mar 23, 2005
34
US
I am looking to take a cell value and return it to a userform. I do not need to edit the value within the form. Just need to return the value, and maintain formating.

At the present time I have the cell value being returned by using making the controlSource of a userform textbox to = data!f8 (the cell to be returned). The issue is I can not control the formating. (need a $ sign)

Thanks for your help.
-bsurfn99
 
What about something like this ?
MsgBox ActiveWorkbook.Sheets("data").Range("F8").Text

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 



Code:
with ActiveWorkbook.Sheets("data").Range("F8")
  txtBox = Format(.Text, .numberformat)
end with


Skip,
[sub]
[glasses] [red][/red]
[tongue][/sub]
 
Thanks for the quick response.

I suppose I should put things into context a little.

I have a userform that I needs to contain the following:

1. Return cell value with formating (showing $). (can be non-editable)
2. Textbox that would allow user to modify the cell value, once submitted. (editable)

If I didn't need to include the textbox for edit, your post would definitely be the ticket. Any ideas for this?

Thanks again.
 
I need to display the current value, and then edit it. I wanted to display the value seperatly from where I enter the new value.

This is what I currently have.

Code:
Private Sub cmd_ok_Click()
    
'for return cell value
    Dim cellvalue As String
    'set textbox value to variable name
    cellvalue = txt_curvalue.Text
    
    Worksheets("data").Cells(8, 6).Value = cellvalue
        
        With Worksheets("data").Cells(8, 6).Value
 '#error#       txt_curvalue = Format(.Text, .NumberFormat) 
        End With
    txt_curvalue.Value = cellvalue
'for updated cell value

    Dim newvalue As String
    'set textbox value to variable name
    newvalue = txt_newvalue.Text
       
    'post data
    Worksheets("data").Cells(8, 4).Value = newvalue

'close form
celllinked.Hide
End Sub
 



" I wanted to display the value seperatly from where I enter the new value."

Then the DISPLAYED value, perhaps, ought to be a LABLE (non-editable) rather than a TextBox (editable).

So what's the PROBLEM?


Skip,
[sub]
[glasses] [red][/red]
[tongue][/sub]
 
Problem = how to apply a cell value to a LABEL within a userform.

If that will allow me to maintain my cell formating. That would be perfect.

Thanks
-bsurfn99
 



I already gave you the answer in my first post.

Skip,
[sub]
[glasses] [red][/red]
[tongue][/sub]
 
I'm sure the answer is within your first post. I haven't used "WITH statements" much though, and must be missing something inorder to get it to work.

I did get the label to work from the cell. So thanks for pointing me in the right direction.

Here is what I ended up with.

Code:
    Dim cellvalue As String
        
    cellvalue = ActiveWorkbook.Sheets("data").Range("F8").Text
    
    Label1.Caption = cellvalue

-bsurfn99
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top