Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VB for Excell 1

Status
Not open for further replies.

Evening

Technical User
Jan 19, 2005
45
0
0
CA
I'd like to make a main menu in Excell like:

MENU
Row Column
B C D
1 Option-1
2 Option-2
3 Oprion-3
4 ----
5 -----

I'd like to iniciate some events with clicking on some field by mouse, or by pressing enter.
So If I click on the B1,(Option-1) it should happen something (Like open a new sheet, calculate something etc...) I can make the programming of what should happen after i clicked on the Option-1 (by recording the macro)
The only problem I dont know how to set-up in VB to iniciate the event.
Could someone show me how to do it?
 



hi,

Your question is not very clear.

You speak of a MENU, which is a ToolBar Item, but then you speak of clicking B1 which is a cell on a sheet.

There are events associated with each worksheet. One event is the Worksheet_SelectionChange event. So if you select a cell, in the event code, you can test to determine if B1 was selected and if so, do whatever it is that you want to happen.

Right-click the sheet tab and select View code. In the code window, select the Object DropDown and select Worksheet. In the Procedure DropDown, select SelectionChange. The target argument is the Selection object.

Skip,
[sub]
[glasses] [red][/red]
[tongue][/sub]
 
I understand Skip what you wrote here. The only thing i don't know how to write it down "TO TEST TO DETERMINE IF B1 WAS SELECTED" Probably some short command, but i don't know jow to program it.
So if I Select The View Code, select Wokrsheet, and SelectChange, how to write it my IF B1 was selected?


Private Sub Worksheet_SelectionChange(ByVal Target As Range)
(case B1 was elected)
( Do this)
(case else
( Do nothing)
End Sub
 


Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    if target.address = range("B1").address then
      ' do if TRUE
    else
      ' do if FALSE
    end if    
End Sub


Skip,
[sub]
[glasses] [red][/red]
[tongue][/sub]
 
Thanks Skip, it's working. If i move the cursor to field B1 for instance, the program iniciates the happenings what i described. In my menu I described 8 items, from B1-B8.
Sometimes it is unexpected that moving the cursor to the next field, immediatelly iniciates the program. Is it possible to change the command that only with mouse double click start the iniciation?
Also can be done in VB to give a command which will save and close the Excell program, by clicking on the last field of my menu?
 



It is possible for you to find the answers your questions yourself.

"Is it possible to change the command that only with mouse double click start the iniciation?"

Did you look at the other events available in the worksheet object?

"Also can be done in VB to give a command which will save and close the Excell program, by clicking on the last field of my menu?"

Can you turn on your macro recorder and record saving your workbook? If you change the destination of the recorded macro from This Workbook, you could record CLOSING your workbook also.


Skip,
[sub]
[glasses] [red][/red]
[tongue][/sub]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top