Home |
Search |
Today's Posts |
#3
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
[Alt]+[F11], as you've seen, opens the Visual Basic for Applications Editor
(VBE). Typically you then use Insert -- Module to create an empty code module to copy and paste code provided here into. But that's not always the case! There are other places that code can reside: Class Modules: very rarely used in these forums. UserForms: again, not used too often in these forums Worksheet code modules - you can tell when code is intended for a worksheet because it will normally start with a statement like Private Sub Worksheet_event() where 'event' is an event that can be recognized by the worksheet such as Activate, Deactivate, Change, SelectionChange and BeforeDoubleClick. The Workbook code module - you can tell when code is intended for a workbook because it will normally start with a statement like Private Sub Workbook_event() where 'event' is an event that can be recognized by the workbook such as _Open, _BeforeClose, _BeforePrint To get to the code modules for the workbook and worksheets, open the VBA Project window in the VBE by pressing the [F4] key if it is not visible. Expand the list of 'Microsoft Excel Objects' in that window. To view the Workbook's code module, double-click on the 'ThisWorkbook' object in the list. To view a specific worksheet's code module, double-click on the desired worksheet name entry. Now for your problem with the Command button code. If you used the command button from the Control Toolbox, the code needs to go into the Worksheet code module for the sheet that the button was placed onto. If you had used the command button from the Forms toolbar, you could have right-clicked it and chosen your macro from a list of available macros. The reason the code you were given did not appear in the list of available macros is because of the word "Private " at the beginning of its definition. When a Sub is identified as Private, it does not appear in that list, nor does it appear in the list of macros using Tools -- Macro -- Macros. Bottom line: delete the code in the regular code module after copying and pasting it into the appropriate worksheet code module and things should work for you. There may already be a code stub for the Command button in that module with nothing but Private Sub CommandButton1_Click() End Sub in it, just paste your code over that. Hope this helps. "CousinExcel" wrote: Hi, Recently KevHardy asked a question with a very nice text and Master Mike H. (who can also inititate chemical reactions in Excel when needed I believe) has given the solution, effective, easily understandable as always. (It was on Feb 11 or 12). The answer was a macro like: "Private Sub CommandButton1_Click() If Selection.Rows.Count 1... In that answer - Alt+F11: I learned it. Then should I say insert MODULE or different ? - Then, I inserted the 'command button' on the worksheet, okay. Right click the 'command button, select 'Assign Macro' then I could not see the macro I wrote ? (I could run it by copying, pasting etc., a long way). Additional question, can I find the list of commands like "Selection.Rows.Count" etc. somewhere in the internet. Thanks and regards, Cousin Excel |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Assigning Macros | Excel Worksheet Functions | |||
Assigning macros | Excel Discussion (Misc queries) | |||
assigning macros | Excel Discussion (Misc queries) | |||
Assigning Macros to Buttons | Excel Discussion (Misc queries) | |||
Problem Assigning Macros | Excel Worksheet Functions |