Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Unload User Form

I have code which displays a user form when a particular cell is activated.
The user may then select a value from a list box in the user form which then
appears in that cell. The user form then unloads when OK/cancel button in
User Form is selected.
However, the user may activate that cell and then choose not to update the
cell value. In this situation I would like the user form to unload without
the user having to click any button/control in the user form but merely by
hitting any arrow key in the keyboard.
Any help would be much appreciated.

The code currently is:

In sheet module:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Address = Range("xxxx").Address Then
SelectAccount
Else: Unload UserForm1
End If
End Sub

In main module:
Sub SelectAccount()
UserForm1.ListBox1.RowSource = Range("xxxxList").Address
UserForm1.ListBox1.ControlSource = Range("xxxx").Address
With UserForm1
.Show vbModeless
.Move 450, 100
End With
End Sub

The code attached to the OK/Cancel buttons is just:
Unload UserForm1

Thanks,
Partho


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Unload User Form

So what isn't working? If you change selection (using an arrow key or
otherwise) and it isn't to cell Range("xxxx") then it should unload
Userform1, even if it has to load it first.

--
Regards,
Tom Ogilvy



"Partho" wrote in message
...
I have code which displays a user form when a particular cell is activated.
The user may then select a value from a list box in the user form which
then
appears in that cell. The user form then unloads when OK/cancel button in
User Form is selected.
However, the user may activate that cell and then choose not to update the
cell value. In this situation I would like the user form to unload without
the user having to click any button/control in the user form but merely by
hitting any arrow key in the keyboard.
Any help would be much appreciated.

The code currently is:

In sheet module:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Address = Range("xxxx").Address Then
SelectAccount
Else: Unload UserForm1
End If
End Sub

In main module:
Sub SelectAccount()
UserForm1.ListBox1.RowSource = Range("xxxxList").Address
UserForm1.ListBox1.ControlSource = Range("xxxx").Address
With UserForm1
.Show vbModeless
.Move 450, 100
End With
End Sub

The code attached to the OK/Cancel buttons is just:
Unload UserForm1

Thanks,
Partho




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Unload User Form

Tom,

The problem is that when the cell is activated and the user form appears,
the user form is the active window. Therefore, when I hit up/down arrow, I
move between the controls in the user form rather than to the next cell in
the worksheet. ideally I would like the user form to be in the 'background'
until the user actually clicks in it.

Partho

"Tom Ogilvy" wrote:

So what isn't working? If you change selection (using an arrow key or
otherwise) and it isn't to cell Range("xxxx") then it should unload
Userform1, even if it has to load it first.

--
Regards,
Tom Ogilvy



"Partho" wrote in message
...
I have code which displays a user form when a particular cell is activated.
The user may then select a value from a list box in the user form which
then
appears in that cell. The user form then unloads when OK/cancel button in
User Form is selected.
However, the user may activate that cell and then choose not to update the
cell value. In this situation I would like the user form to unload without
the user having to click any button/control in the user form but merely by
hitting any arrow key in the keyboard.
Any help would be much appreciated.

The code currently is:

In sheet module:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Address = Range("xxxx").Address Then
SelectAccount
Else: Unload UserForm1
End If
End Sub

In main module:
Sub SelectAccount()
UserForm1.ListBox1.RowSource = Range("xxxxList").Address
UserForm1.ListBox1.ControlSource = Range("xxxx").Address
With UserForm1
.Show vbModeless
.Move 450, 100
End With
End Sub

The code attached to the OK/Cancel buttons is just:
Unload UserForm1

Thanks,
Partho





  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Unload User Form

You can use AppActivate to re-activate Excel after you show the
form. E.g., something like


Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Address = "$C$3" Then
UserForm1.Show vbModeless
AppActivate Application.Caption
End If
End Sub


Adjust to your code.

Of course if the user wants to enter a value, then they would have to click
in the form.



--

Regards,

Tom Ogilvy







"Partho" wrote in message
...
Tom,

The problem is that when the cell is activated and the user form appears,
the user form is the active window. Therefore, when I hit up/down arrow, I
move between the controls in the user form rather than to the next cell in
the worksheet. ideally I would like the user form to be in the
'background'
until the user actually clicks in it.

Partho

"Tom Ogilvy" wrote:

So what isn't working? If you change selection (using an arrow key or
otherwise) and it isn't to cell Range("xxxx") then it should unload
Userform1, even if it has to load it first.

--
Regards,
Tom Ogilvy



"Partho" wrote in message
...
I have code which displays a user form when a particular cell is
activated.
The user may then select a value from a list box in the user form which
then
appears in that cell. The user form then unloads when OK/cancel button
in
User Form is selected.
However, the user may activate that cell and then choose not to update
the
cell value. In this situation I would like the user form to unload
without
the user having to click any button/control in the user form but merely
by
hitting any arrow key in the keyboard.
Any help would be much appreciated.

The code currently is:

In sheet module:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Address = Range("xxxx").Address Then
SelectAccount
Else: Unload UserForm1
End If
End Sub

In main module:
Sub SelectAccount()
UserForm1.ListBox1.RowSource = Range("xxxxList").Address
UserForm1.ListBox1.ControlSource = Range("xxxx").Address
With UserForm1
.Show vbModeless
.Move 450, 100
End With
End Sub

The code attached to the OK/Cancel buttons is just:
Unload UserForm1

Thanks,
Partho







  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Unload User Form

Tom,

AppActivate fixes my problem! Thanks for your help!

Partho

"Tom Ogilvy" wrote:

You can use AppActivate to re-activate Excel after you show the
form. E.g., something like


Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Address = "$C$3" Then
UserForm1.Show vbModeless
AppActivate Application.Caption
End If
End Sub


Adjust to your code.

Of course if the user wants to enter a value, then they would have to click
in the form.



--

Regards,

Tom Ogilvy







"Partho" wrote in message
...
Tom,

The problem is that when the cell is activated and the user form appears,
the user form is the active window. Therefore, when I hit up/down arrow, I
move between the controls in the user form rather than to the next cell in
the worksheet. ideally I would like the user form to be in the
'background'
until the user actually clicks in it.

Partho

"Tom Ogilvy" wrote:

So what isn't working? If you change selection (using an arrow key or
otherwise) and it isn't to cell Range("xxxx") then it should unload
Userform1, even if it has to load it first.

--
Regards,
Tom Ogilvy



"Partho" wrote in message
...
I have code which displays a user form when a particular cell is
activated.
The user may then select a value from a list box in the user form which
then
appears in that cell. The user form then unloads when OK/cancel button
in
User Form is selected.
However, the user may activate that cell and then choose not to update
the
cell value. In this situation I would like the user form to unload
without
the user having to click any button/control in the user form but merely
by
hitting any arrow key in the keyboard.
Any help would be much appreciated.

The code currently is:

In sheet module:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Address = Range("xxxx").Address Then
SelectAccount
Else: Unload UserForm1
End If
End Sub

In main module:
Sub SelectAccount()
UserForm1.ListBox1.RowSource = Range("xxxxList").Address
UserForm1.ListBox1.ControlSource = Range("xxxx").Address
With UserForm1
.Show vbModeless
.Move 450, 100
End With
End Sub

The code attached to the OK/Cancel buttons is just:
Unload UserForm1

Thanks,
Partho








Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to unload a form in excel vba? Edward[_7_] Excel Programming 2 September 30th 04 04:39 PM
Unload the form on esc key Papou Excel Programming 0 August 10th 04 05:15 PM
Load and Unload Form commands R Avery Excel Programming 4 July 29th 04 03:16 PM
form won't unload inquirer Excel Programming 1 May 26th 04 09:55 AM
Form Unload Khai[_2_] Excel Programming 0 August 4th 03 09:28 PM


All times are GMT +1. The time now is 03:47 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"