cell content in textbox on userform....

ExcelNovice

Well-known Member
Joined
May 12, 2002
Messages
583
All, I'm trying to display the content of a number of cells in different textboxes on a VBA Userform.

On the userform are different textboxes:
For textbox1: need VBA to display the content of cell cg220
For textbox2: need VBA to display the content of cell cg221

and so on....

Thanks for your help.
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
If you buttons are always TextBox1, TextBox2 .... TextBoxX then you could try code like this in your UserForm code module which will load the values automatically when the UserForm is shown . It will exit on an invalid (ie non existent) Textbox fill

Pl note this code loads the cell contents from the first sheet of the workbook containing the UserForm

hth

Dave

Code:
Private Sub UserForm_Activate()
    Dim ws As Worksheet
    Dim lngRow As Long
    Set ws = ThisWorkbook.Sheets(1)
    On Error Resume Next
    Do
        lngRow = lngRow + 1
        Me.Controls("Textbox" & lngRow).Value = ws.Range("cg220").Offset(lngRow - 1, 0)
    Loop While Err.Number = 0
End Sub
 
Upvote 0
Brettdj, thanks....this is close to the solution, but using it I'm unable to restrict specific cell content to specific textbox; how do I do that?
 
Upvote 0
More simply:-
Code:
Private Sub UserForm_Activate()
 
    Dim ws As Worksheet
 
    Set ws = ThisWorkbook.Sheets(1) [COLOR=green]' this points to the worksheet containing the data to be displayed[/COLOR]
 
    textbox1=ws.range("cg220")
    textbox2=ws.range("cg221")
   [COLOR=green]' ...etc[/COLOR]
    textbox99=ws.range("zz999")
 
End Sub
 
Upvote 0
Brettdj, thanks....this is close to the solution, but using it I'm unable to restrict specific cell content to specific textbox; how do I do that?
Hi, well as you seemed to be providing a regular pattern I coded for that rather than building a long hardcoded fixed list - but if thats what you actually needed if there wasn't a repeatable pattern then Ruddles has provided it

Cheers

Dave
 
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,277
Members
452,902
Latest member
Knuddeluff

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top