Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

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

Status
Not open for further replies.

bin

Computer
Jul 16, 2001
1
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.
 
Replies continue below

Recommended for you

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
 
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...


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor