Load into textbox two values from customer on worksheet

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
5,731
Office Version
  1. 2007
Platform
  1. Windows
Hi,
I have a customers name in cell G13 example TOM JONES 001 on worksheet INV
I open a userform & i need 2 TextBoxes to be populated with values from my worksheet for TOM JONES 001

It should work like this.
On worksheet INV in cell G13 take note of customers name.
Look for this customers name on worksheet DATABASE in column A
Once found the values needed are in column C for TextBox3 & column K for TextBox2

Thanks please advise.

I was using the below but the name in question works if on row 6
Rich (BB code):
Private Sub UserForm_Initialize()

    Me.StartUpPosition = 0
    Me.Top = Application.Top + 210  ' MARGIN FROM TOP OF SCREEN
    Me.Left = Application.Left + Application.Width - Me.Width - 350 ' LEFT / RIGHT OF SCREEN

    TextBox2.Value = Sheets("DATABASE").Range("K6").Value
    TextBox3.Value = Sheets("DATABASE").Range("C6").Value

End Sub
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
Not sure if im heading the right way but i have this below which will find the value in cell G13 on the worksheet in question.

Not sure how i edit / add to it so TextBox2 & TextBox3 get the values needed.
Basically Customers name in cell then offset by 3 for TextBox3 & offset by 11 for TextBox2 ?

VBA Code:
  Dim findString As String
  Dim rng As Range
  findString = Range("G13").Value
    With Sheets("DATABASE").Range("A:A")
    Application.EnableEvents = False
   Set rng = .Find(What:=findString, After:=.Cells(.Cells.count), LookIn:=xlValues, _
              LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False)
    If Not rng Is Nothing Then
      Application.Goto rng, True
     Else
      MsgBox "CUSTOMER NOT FOUND"
    End If
    Application.EnableEvents = True
  End With

I understand my code takes me to the cell & its not needed but im just trying to work it through
 
Upvote 0
VBA Code:
Private Sub UserForm_Initialize()

    Dim Customer  As String
    Dim Found     As Range

    Me.StartUpPosition = 0
    Me.Top = Application.Top + 210  ' MARGIN FROM TOP OF SCREEN
    Me.Left = Application.Left + Application.Width - Me.Width - 350    ' LEFT / RIGHT OF SCREEN

    Customer = Sheets("INV").Range("G13").Value

    With Sheets("DATABASE")

        Set Found = .Columns("A").Find(Customer, , xlValues, xlWhole, 0, 0, 0)

        If Not Found Is Nothing Then

            TextBox2.Value = .Range("K" & Found.Row).Value
            TextBox3.Value = .Range("C" & Found.Row).Value

        Else

            MsgBox Customer, vbExclamation, "No Match Found"

        End If
    End With
End Sub
 
Upvote 0
Solution
Hi,
Straight away i see Subscript out of range.
This line is then shown in yellow.
Rich (BB code):
Set Found = .Columns("A").Find(Customer, , xlValues, xlWhole, 0, 0, 0)
 
Upvote 0

Forum statistics

Threads
1,223,883
Messages
6,175,167
Members
452,615
Latest member
bogeys2birdies

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