×
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

Absolute & Relative References (Excel 97 Macro help, please)

Absolute & Relative References (Excel 97 Macro help, please)

Absolute & Relative References (Excel 97 Macro help, please)

(OP)
In programming a macro, I would like to have an ABSOLUTE column reference, with a REALITIVE row.

   Example,

   I have 4 column locations I want to go (ie. C,Z,BB,CD). I want to make 4 seperate macros to go to the 4 seperate locations, with the following
   condiditions:

   a) I want to mantain my row position (ie. if the ActiveCell is "C11" and I run the "Z" macro, I want my final resting point to be "Z11"

   b) I want to be able to run the 4 macros in ANY order (This is the part I am having trouble with)


   One possible solution I had was if there were some command (within VB) that would sense where the ActiveCell was and be able to return a
   row/column value. I could then use these values in a formula that would end up using the Scroll to move the screen accordingly command.

   I am really in a jam on this, so I would appreciate any help or advice that you could provide.

RE: Absolute & Relative References (Excel 97 Macro help, please)

I think it's not so big a problem. I only wonder if you are programming in VB or you are programming in Excel using VB for Applications. Because if you're programming in VBA then there is an easy solution:

ActiveCell.Address wil give you the absolute adress of the highlighted cell.

To get the Row or the Column simply change Address in to Row or Column.

The return types of the Adress function is Range. This is just a string. For the Row and Coumn function the return type is a LongInt.

For example the highlighted cell is C11. ActiveCell.Address would return "$C$11", while ActiveCell.Row would give the number 11.

Now I think it's not so hard to select the right column on the right row.

Good luck!

Jonathan

RE: Absolute & Relative References (Excel 97 Macro help, please)

Cactus13 has explained it very well. I'll just add something on how the macros should be organised:

Say we have the following Macros: MacroC, MacroZ, MacroBB, MacroCD - the names can be anything - I've just named them so their target column would be obvious. You'd write the code something like this:

In the Declaration Section of the module, put the statement:
Dim TargetCell as Range

Then write the macros:

Sub MacroC
  Set TargetCell=Activesheet.Cells(Activecell.row,Columns("C:C").Column)
Do what u want with TargetCell in the statements that follow...
End Sub


Sub MacroZ
  Set TargetCell=ActiveSheet.Cells(ActiveCell.row,Columns("Z:Z").Column)
Do what u want with TargetCell in the statements that follow...
End Sub

and so on...

Note that there's really no need to refer to the columns as "C:C" or "Z:Z" - simply using "C" or "Z" will also do.

All the best...


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