Using TextBox data from user form to find cell in column

dannyh

Board Regular
Joined
Oct 15, 2007
Messages
156
Hi All

I have a simple loop looking for a date in a column based on whatever is typed in the Text Box in my user form, I know the date is there but it just keeps looping past it. I have tried testing putting in a simple number “5” and searching for that and again it fails. Is there any other tests I can do ?

My loop code
Code:
Rng = UserForm3.TextBox1
Range(“A1”).select
Do Until ActiveCell.Value = Rng
ActiveCell.Offset(1,0)
Loop

Thanks Dan
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Sorry still do not understand
You want to search for value entered in TextBox1 and do what when found.
And do you want to find this value in column A of active sheet
You want to paste the Range Sheets("Data").Range("G5:O5")
 
Upvote 0
Try:
Code:
Sub Macro1()

On Error Resume Next
[A:A].Find(UserForm3.TextBox1, , xlFormulas, xlPart).Offset(1).Resize(, 9).Value = Sheets("Data").[G5:O5].Value
On Error GoTo 0

End Sub
 
Upvote 0
Sorry still do not understand
You want to search for value entered in TextBox1 and do what when found.
And do you want to find this value in column A of active sheet
You want to paste the Range Sheets("Data").Range("G5:O5")
Sorry, i'll try again,

Search for value in TextBox1 in Col A on active sheet
Once the value is found I would like to past the range G5:O5 on Sheet "DATA" into the cells directly next to the found value, eg if the found value is in A7 then paste range from DATA sheet into B7:K7
 
Upvote 0
Try:
Code:
Sub Macro1()

On Error Resume Next
[A:A].Find(UserForm3.TextBox1, , xlFormulas, xlPart).Offset(1).Resize(, 9).Value = Sheets("Data").[G5:O5].Value
On Error GoTo 0

End Sub

Hi Jack

I tried your solution still no luck, the code cycles through but doesn't find the date that is there, I have tried changing the word to text and it does find that but it inserts the copied data below the cell not to the side of it so I just need to change the offset.
 
Upvote 0
Hi @dannyh

For side of it, try:
VBA Code:
Sub Macro1()

On Error Resume Next
[A:A].Find(UserForm3.TextBox1, , xlFormulas, xlPart).Offset(,1).Resize(, 9).Value = Sheets("Data").[G5:O5].Value
On Error GoTo 0

End Sub
Unsure about not finding date, could be the format of values in column A are not set to date or the value being searched for isn't recognised as a date.

As a guess, I've commented out the error surpressions and forced the search to be a date, try:
VBA Code:
Sub Macro1()

'On Error Resume Next
With UserForm3
    [A:A].Find(DateSerial(Year(.TextBox1), Month(.TextBox1), Day(.TextBox1)), , xlFormulas, xlPart).Offset(, 1).Resize(, 9).Value = Sheets("Data").[G5:O5].Value
End With
'On Error GoTo 0

End Sub
 
Upvote 0

Forum statistics

Threads
1,215,073
Messages
6,122,977
Members
449,095
Latest member
Mr Hughes

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