Get value from worksheet to userform on another worksheet

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
5,832
Office Version
  1. 2007
Platform
  1. Windows
I am on a worksheet called QUOTES.
I select a customer in cell A4
This customer is TOM JONES
I click a command button which opens another worksheet in the same workbook called DATABASE & then opens a userform.

My question is please advise a code that will put the selected customers name in this case TOM JONES into the userform TextBox1
Userform is called DatabaseUserForm

Thanks
 
OK
So i have put those codes in place but i see that the TextBox1 is being picked up from the DATABASE sheet.

I found this whilst looking for an issue.

Looking at the code towards the end i see 000
The codes looks down column A to see if the name in TextBox1 has been a past customer & if so depending on how many times the values are added.
So TOM JONES 001 002 003 etc

I thought that TextBox 1 would be the customer that was selected on the QUOTES sheet than on the DATABASE sheet the code would look for a past purchase etc

VBA Code:
Private Sub TextBox1_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean)
    Dim fndRng As Range
    Dim findString As String
    Dim i As Integer
    Dim wsPostage As Worksheet
    
    findString = Me.TextBox1.Value
    If Len(findString) = 0 Then Exit Sub
    
    Set wsPostage = ThisWorkbook.Worksheets("DATABASE")
    i = 1
    Do
        Set fndRng = Nothing
        Set fndRng = wsPostage.Range("A:A").Find(What:=findString & Format(i, " 000"), _
                                                    LookIn:=xlValues, LookAt:=xlWhole, SearchOrder:=xlByRows, _
                                                    SearchDirection:=xlNext, MatchCase:=False)
        If Not fndRng Is Nothing Then
            i = i + 1
            Cancel = True
        End If
    Loop Until fndRng Is Nothing
    
    Me.TextBox1.Value = findString & Format(i, " 000")
    Cancel = False
    
End Sub
 
Upvote 0

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
When the userform opens TextBox1 needs to show the customers name that was selected on the sheet QUOTES Then look for a match on the DATABASE sheet & add 001 002 etc
Thanks
 
Upvote 0
You didn't remove the crossed out lines from your SendToDatabase2_Click sub did you ?

Do the codes below not give what you expect in TextBox1 ?
VBA Code:
Private Sub SendToDatabase2_Click()
' declare variables
    Dim answer As Integer
    Dim r As Long
' check for column of active cell
If ActiveCell.Column = 1 Then
    ' if column 1 ask
    answer = MsgBox("SEND DETAILS TO DATABASE ? ", vbYesNo + vbInformation, "OPEN DATABASE MESSAGE")
    ' if answer is yes
    If answer = vbYes Then
        ' show the user form
        DatabaseUserForm2.Show
    End If
Else
    ' message if active cell was not in column 1
    MsgBox "YOU NEED TO SELECT A CUSTOMER IN COLUMN A", vbCritical, "SELECT CUSTOMER MESSAGE"
End If
Exit Sub

End Sub

VBA Code:
Private Sub UserForm_Initialize()
    ' hide DatabaseSheetTransferButton
    DatabaseSheetTransferButton.Visible = False
    ' populate TextBox1 from ActiveCell
    Me.TextBox1.Text = ActiveCell.Value
    ' change active sheet to "DATABASE"
    ActiveWorkbook.Sheets("DATABASE").Activate
End Sub
 
Upvote 0
Solution
Nope i copied from the page & just pasted.
Ive now copied the above & now it works.

I will paly with it a bit & mark as ok once im happy.

Many Thanks for your time.

I will make a new post once im happy here with how to then delete that selected customer from sheet QUOTES once the above has been completed.
 
Upvote 0

Forum statistics

Threads
1,224,825
Messages
6,181,191
Members
453,021
Latest member
pingpong7117

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