×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

What about macros
2

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)?

RE: What about macros

Check out "Writing Excel Macros" from O'Reilly publishing.

RE: What about macros

MACRO PERFORMING ON ACTIVE WORKSHEET

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

When you write a XL macro  to do something, there are several basic things you must take care of including the sheet for which it is supposed to run:
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

Can somebody let me know please how can I pick a particulr value from a range against a particular value. For instance If I am using  from Menue, Data> Validation> Pick from List, and I have 2 colums in the list having particular value against a particular vriable, how can I put value against a particular variable in my required cell.
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

You should check out VLOOKUP or HLOOKUP in the help menu.

RE: What about macros

Use Lookup function

=LOOKUP(C1,A1:A3,B1:B3)

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources