Store Userform textbox value

KittyS

New Member
Joined
May 25, 2012
Messages
18
I am new to using userforms and struggling.. so if anybody has a tip:

I want the user to input a (week)number in a userform and then find this number in my worksheet. I can't seem to match the userform value with the sheet value.

Code is as follows:

Private Sub OK_Click()

Range("A8").Select
ActiveCell(1, 14).Select
If ActiveCell.Value = Planweeknr.Value Then
ActiveCell.Rows("1:1").EntireRow.Select
Selection.Copy

End If


please?
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Welcome to the Forum KittyS. You could look to record a macro using the find command and then adapt that to the field name. Example below I have named a textbox as txtWeekNu

Private Sub cmdOK_Click()
Sheets("Sheet3").Select
Cells.Find(What:=Me.txtWeekNu.Value, After:=ActiveCell, LookIn:=xlFormulas, LookAt:= _
xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
, SearchFormat:=False).Activate
ActiveCell.EntireRow.Select


End Sub
 
Upvote 0
Hi Trevor,

Thanks for your reply. However, I can't get it to work. I put planningweeknr in the sheet on "10". When I want the userform textbox entry "10" to be found in my sheet it doesn't find it. This is the whole code so far. I need a way to store the planningweeknumber somewhere in a variable, and then search for this same variable in the sheet.
help..:confused:

Private Sub OK_Click()
If Planweeknr.Value = "" Then
Planweeknr.SetFocus
MsgBox "Please enter a week number!", vbExclamation
End If
Cells.Find(What:=Me.Planweeknr.Value, After:=ActiveCell, LookIn:=xlFormulas, LookAt:= _
xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
, SearchFormat:=False).Activate
Range("A8").Select
ActiveCell(1, 14).Select
If ActiveCell.Value = Me.Planweeknr.Value Then
ActiveCell.Rows("1:1").EntireRow.Select
Selection.Copy
 
Upvote 0
Are the values on the worksheet text like the value in the textbox is?
 
Upvote 0

Forum statistics

Threads
1,215,181
Messages
6,123,508
Members
449,101
Latest member
mgro123

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