Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 26
Default How to get from inside a VB macro the currently marked cell?

Both suggested commands do NOT work.
If I use them e.g. in a command like:

Set baseCell = ActiveSheet.Range(Activecell)

or

Set baseCell = ActiveSheet.Range(Selection.cells(1))

then Excel crashes with the following popup:

"Run-time error '1004':
Application defined of object-defined error"

What's wrong?

Other possibilities of getting the currently marked cell?

Claudia

Maybe

Activecell
or
Selection.cells(1)

Claudia d'Amato wrote:

Assume I have opened a worksheet and marked exactly one cell (e.g. D47).

Now I want to run a VB macro. How can I find out from inside this macro
which cell is currently marked in the current worksheet?

This should look similar to:

Set baseCell = ActiveSheet.Range(getcurrentlymarkedcell())

Obviously "getcurrentlymarkedcell()" does not exists. Which function can I use instead?

If the user accidentially marked a range of cells instead of a single cell then only the
first/upper+leftmost cell should be returned.

Claudia


--

Dave Peterson

  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default How to get from inside a VB macro the currently marked cell?

Set baseCell = Activecell
or
Set baseCell = Selection.cells(1)

=====
When you do this:
Set baseCell = ActiveSheet.Range(Activecell)
it's the equivalent of:
Set baseCell = ActiveSheet.Range(Activecell.value)

If the value in the activecell looks like an address (B5 or 3:8 or x:z), then
it'll work--but probably(!) not what you want.

If the value in the activecell is anything else (a number, a string, an error,
....), then it'll fail.

Claudia d'Amato wrote:

Both suggested commands do NOT work.
If I use them e.g. in a command like:

Set baseCell = ActiveSheet.Range(Activecell)

or

Set baseCell = ActiveSheet.Range(Selection.cells(1))

then Excel crashes with the following popup:

"Run-time error '1004':
Application defined of object-defined error"

What's wrong?

Other possibilities of getting the currently marked cell?

Claudia

Maybe

Activecell
or
Selection.cells(1)

Claudia d'Amato wrote:

Assume I have opened a worksheet and marked exactly one cell (e.g. D47).

Now I want to run a VB macro. How can I find out from inside this macro
which cell is currently marked in the current worksheet?

This should look similar to:

Set baseCell = ActiveSheet.Range(getcurrentlymarkedcell())

Obviously "getcurrentlymarkedcell()" does not exists. Which function can I use instead?

If the user accidentially marked a range of cells instead of a single cell then only the
first/upper+leftmost cell should be returned.

Claudia


--

Dave Peterson


--

Dave Peterson
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to get from inside a VB macro the currently marked cell? Claudia d'Amato Excel Discussion (Misc queries) 2 September 22nd 09 03:54 PM
Marking cell; totaling all # between marked cell & next marked cel Marley Excel Worksheet Functions 4 February 26th 09 01:26 AM
Bar graph with percentage of total marked inside each bar Kristin Charts and Charting in Excel 0 February 22nd 08 07:00 PM
using a cell value to control a counter inside a macro and displaying macro value ocset Excel Worksheet Functions 1 September 10th 06 05:32 AM
Macro Inside Cell dah Excel Discussion (Misc queries) 3 January 23rd 06 09:08 PM


All times are GMT +1. The time now is 11:14 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"