What about macros
What about macros
(OP)
I started to develop macros in EXCELL spreedsheets for particular aplications and soon realized that they are tricky.
I learned that you must execute macros locating (the cursor) in the sheet it is supposed to start, otherwise you woul watch it perform the operation over the wrong selection, for example.
What else is there about macros to watch out (apart from the virus issue)?
I learned that you must execute macros locating (the cursor) in the sheet it is supposed to start, otherwise you woul watch it perform the operation over the wrong selection, for example.
What else is there about macros to watch out (apart from the virus issue)?





RE: What about macros
RE: What about macros
This is the default when you do not specify the kind of xls file or the workbook or the worksheet on which the macro is to operate.
If it causes problems, you may put a message box into the macro asking for varification of the active sheet.
You can even make the macro to check the xls file name or the sheet name before going on.
But as I said, for most operations, it is just great to have the macro run on the active workbook.
Compares to the Print tool that asks no questions - a bit annoying at first but very practical later.
RE: What about macros
To cite one -
If the macro is intended to work on a range and the selection is an object, it'll screech to a halt with a suitable msg if the VBA code refers to the 'Selection' object. In such cases, its a good idea to incorporate in the macro, code to identify the type of selection before the main body of the code runs.. use typename
For example, exit the procedure without doing anything
Sub XYZ()
If typename(selection)<>"Range" then Exit Sub '
Other statements...
End Sub
OR Display a helpful msg
Sub XYZ()
If typename(selection)<>"Range" then msgbox("Select a range and try again")
Other statements...
End Sub
RE: What about macros
An example is :
Pipe Actual
Nominal Dia Inside Dia
2 2.067
2 1/2 2.469
3 3.068
I want to pick 3 and want the value 3.068 in my required cell. I shall be thankful for the help anybody can give me.
RE: What about macros
RE: What about macros
=LOOKUP(C1,A1:A3,B1:B3)