Using UF information in a macro

RusheR

Board Regular
Joined
Feb 18, 2008
Messages
97
I have a Macro that brings up a userform.

HTML:
'Run UserForm
    UserForm_SelectAccount.Show

In that UF I have a combobox that lists bank accounts. I want the bank account that's chosen to be then thrown over into my macro where it uses the data.

I can't figure out how to do this (past a very primative way of copying the data to the sheet in the UF then when the macro finishes it gets the data and clears it.

Can anyone please help?

I though this would work but it doesn't...

HTML:
MsgBox (UserForm_SelectAccount.ComboBox_Accounts.Text)
 
It's an external module.

I run the macro than it brings up the UF. Once the user form is finished it goes back to the macro and picks up where it left off.

THis is the only way I know how to do it.
 
Upvote 0
You could try declaring a variable in the main macro, then assigning the ComboBox text to that variable while the UserForm is still up. That way, when the form is closed, the text should be retained in memory.
 
Upvote 0
That doesn't seem to work.

This is my macro...

Dim AccountName As String
'Run UserForm
UserForm_SelectAccount.Show

MsgBox (AccountName)

and this is my userform...

Private Sub CommandButton_Okay_Click()

AccountName = ComboBox_Accounts.Value
Unload Me
Exit Sub
End Sub

Any idea why it's not working???
 
Upvote 0
Hi,

You'll need to do something like this:

In Userform:
Code:
Option Explicit

Private Sub btnExit_Click()
Me.Hide
End Sub

Private Sub ComboBox_Accounts_Change()
btnExit.Enabled = ComboBox_Accounts.ListIndex >= 0
End Sub

Private Sub UserForm_Initialize()
With ComboBox_Accounts
    .AddItem "A"
    .AddItem "B"
    .AddItem "C"
End With
btnExit.Enabled = False
End Sub
'*** disable close via little 'x' ***
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
    If Cancel <> 1 Then
    Cancel = -1
    End If
End Sub

The calling code:
Code:
Dim frmSelAccounts As Userform_SelectAccounts

Set frmSelAccounts = New Userform_SelectAccounts
frmSelAccounts.Show
MsgBox frmSelAccounts.ComboBox_Accounts.Value
Set frmSelAccounts = Nothing
 
Upvote 0

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