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
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
So i can work out how to get the value of the active cell into the textbox for the worksheet DATABASE

Using this here.
VBA Code:
Private Sub UserForm_Initialize()
DatabaseSheetTransferButton.Visible = False
Me.TextBox1.Text = ActiveCell.Value
End Sub

BUT

I need it from the worksheet QUOTES that ive just come from.
I thought this might do it but ive got it wrong somewhere ??

Code:
Private Sub UserForm_Initialize()
DatabaseSheetTransferButton.Visible = False
Me.TextBox1.Text = ThisWorkbook.Worksheets("QUOTES").ActiveCell.Value
End Sub

Do you see the mistake,Thanks
 
Upvote 0
I can get a static address value to work but not activecell ?

VBA Code:
Private Sub UserForm_Initialize()
DatabaseSheetTransferButton.Visible = False
Me.TextBox1.Text = Worksheets("QUOTES").Range("A3").Value
End Sub
 
Upvote 0
Suspect the issue is between the click of the button and opening of the userform.

If you're wanting to use active sheet in UserForm_Initialize, don't
opens another worksheet in the same workbook called DATABASE
until just before End Sub in UserForm_Initialize
 
Upvote 0
Not sure I understand that.
In my code A3 is the fixed location.

I want it to be the location at which it was selected on the original sheet.

So my code works fine apart from it will always get the value from cell A3

I’m looking that if I select A22 then that value is used or if I select A256 then that value is used.

I’m not sure how to write that & it’s not a case of it not working. I could only figure out how to write it by using A3 or A4 or A5 I want the code written so it remembers the cell in column A that was selected & put that value in the Textbox.
 
Upvote 0
Here is the code that i have at present.
As mentioned i can only write it so that no matter what customer i select in column A it will always be the customer in cell A3 NICOLA TEST NAME.

Example i wish to select customer in cell A6 BOBBY SINGH & have his details placed in the textBox.
This is why in my code A3 cant be used & maybe active cell from worksheet QUOTES.

Thanks



VBA Code:
Private Sub SendToDatabase2_Click()
Dim answer As Integer
Dim r As Long
If ActiveCell.Column = 1 Then
answer = MsgBox("SEND DETAILS TO DATABASE ? ", vbYesNo + vbInformation, "OPEN DATABASE MESSAGE")
If answer = vbYes Then
ActiveWorkbook.Sheets("DATABASE").Activate
DatabaseUserForm2.Show
End If
Else
MsgBox "YOU NEED TO SELECT A CUSTOMER IN COLUMN A", vbCritical, "SELECT CUSTOMER MESSAGE"
End If
Exit Sub

End Sub
 

Attachments

  • EaseUS_2024_07_18_09_22_34.jpg
    EaseUS_2024_07_18_09_22_34.jpg
    49.2 KB · Views: 7
  • EaseUS_2024_07_18_09_25_22.jpg
    EaseUS_2024_07_18_09_25_22.jpg
    30.8 KB · Views: 6
Upvote 0
Yup, exactly as suspected in post 4

Don't activate the DATABASE sheet until after TextBox1 is loaded in UserForm_Initialize
 
Upvote 0
Im well confused please3 show me what i need to do as i still think after that its different to what im looking for
 
Upvote 0
Rich (BB 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
        ' change active sheet to "DATABASE"
        ActiveWorkbook.Sheets("DATABASE").Activate
        ' 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

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