Code not formatting correctly in textbox userform

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
5,730
Office Version
  1. 2007
Platform
  1. Windows
On my worksheet i have a table of customers with their values.

I have a useform of which the code is shown below.
My issue is TextBox4

I open the userform & enter a customers ID number & then the form is populated.
So in this example i enter 1 & i see the textboxes are populated.
I look at Textbox4 & i see £25.00

Lets say i now close the userform, on my worksheet i change the value of £25.00 to £20.00

Now i expect that when i open the userform & enter 1 again that Textbox4 should show £20.00 BUT i see 20

This pattern seems to be the same for any customer.
If i cgange the value on the worksheet then open the userform i only see example 35 as opposed £35.00 or 50 as oppose £50.00

Do you see wht the correct item isnt be displayed when userform is open.





Rich (BB code):
Private Sub CustomerID_Change()
    Dim id As Variant, rowcount As Long, foundcell As Range
    Dim lRow As Long
    Dim i As Long
    
    On Error Resume Next
    id = CLng(CustomerID.Value)
    
    If Err.Number <> 0 Then
        id = 0
    End If
    On Error GoTo 0
    SpinButton1.Value = id

    rowcount = Sheets("G INCOME").Cells(Rows.Count, 13).End(xlUp).Row    ' THIS IS COLUMN NUMBER WHERE CUSTOMER ID IS LOCATED


    With Worksheets("G INCOME").Range("M1:M" & rowcount)    ' THIS IS CELL REFERENCE OF WHERE THE TEXT CUSTOMER ID IS LOCATED
        Set foundcell = .Find(what:=id, LookIn:=xlValues)
    
        If Not foundcell Is Nothing Then
            lRow = foundcell.Row
            For i = 1 To 5
                Me.Controls("TextBox" & i).Value = .Cells(lRow, i + 1)
            Next i

        Else

            For i = 1 To 5
                Me.Controls("TextBox" & i).Value = vbNullString
            Next i
        End If
    End With

End Sub
 
This works but should i use yours ?
Use the one that you feel most comfortable with (the code Micron posted is more efficient but you are only dealing with 5 text boxes so you probably won't notice the difference)
 
Upvote 0

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.

Forum statistics

Threads
1,223,867
Messages
6,175,069
Members
452,611
Latest member
bls2024

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