Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 25
Default Novice VBA question...

Hello

I am 3 weeks into learning VBA so knowledge is low.
Still, how do I get VBA to return the cell reference of
an activecell?

If I click on, say, cell B10 how can I get VBA to
register that? The reason is, say I click on cell B10, I
want that to trigger VBA to bring up a MsgBox. But I
can't find a way for VBA to recognise that cell B10 has
been 'clicked upon'!

I just can't find away in which VBA will recognise cell
references.

Suppose, cell B10 has the value 5. If I type...

MsgBox Range("B10").Value

Then I get a MsgBox showing 5. But suppose I wanted VBA
to tell me which cell in a worksheet contained the value
5 (assuming there is only one).

Any thoughts out there?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Novice VBA question...

Try referencing the address property of the range or cell
object. For example, try the following code:

If ActiveCell.Value = 5 Then MsgBox ActiveCell.Address

OR

If Range("B10").Value = 5 Then MsgBox Range("B10").Address

Hope that helps.

-----Original Message-----
Hello

I am 3 weeks into learning VBA so knowledge is low.
Still, how do I get VBA to return the cell reference of
an activecell?

If I click on, say, cell B10 how can I get VBA to
register that? The reason is, say I click on cell B10, I
want that to trigger VBA to bring up a MsgBox. But I
can't find a way for VBA to recognise that cell B10 has
been 'clicked upon'!

I just can't find away in which VBA will recognise cell
references.

Suppose, cell B10 has the value 5. If I type...

MsgBox Range("B10").Value

Then I get a MsgBox showing 5. But suppose I wanted VBA
to tell me which cell in a worksheet contained the value
5 (assuming there is only one).

Any thoughts out there?
.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,718
Default Novice VBA question...

If I click on, say, cell B10 how can I get VBA to register that?

clicking a cell in itself is not an "event", but selecting a cell/range is
(by mouse or by keyboard).

Right click on a worksheet tab and pick View Code. This will open the
worksheet's code module. In the left drop down at the top of the module,
select worksheet. In the right drop down will appear all the "events" that
Excel will call your code for.

SelectionChange is the event that appears in the module by default. Add
code so it looks like this:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
MsgBox Target.Address
End Sub

Now return to Excel and select some ranges.

--
Jim Rech
Excel MVP
"Alex" wrote in message
...
| Hello
|
| I am 3 weeks into learning VBA so knowledge is low.
| Still, how do I get VBA to return the cell reference of
| an activecell?
|
| If I click on, say, cell B10 how can I get VBA to
| register that? The reason is, say I click on cell B10, I
| want that to trigger VBA to bring up a MsgBox. But I
| can't find a way for VBA to recognise that cell B10 has
| been 'clicked upon'!
|
| I just can't find away in which VBA will recognise cell
| references.
|
| Suppose, cell B10 has the value 5. If I type...
|
| MsgBox Range("B10").Value
|
| Then I get a MsgBox showing 5. But suppose I wanted VBA
| to tell me which cell in a worksheet contained the value
| 5 (assuming there is only one).
|
| Any thoughts out there?


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
A macro code question from a novice Richard Excel Discussion (Misc queries) 2 December 24th 07 07:22 PM
Novice formula question Denise Excel Discussion (Misc queries) 10 November 7th 07 08:43 AM
Novice IF and COUNT question (I think) Robin Excel Worksheet Functions 5 October 3rd 07 11:00 PM
Excel Novice, Stupid Question, but help! [email protected] Excel Discussion (Misc queries) 6 February 13th 06 03:14 AM
drop down list - a question from novice striker_69 Excel Discussion (Misc queries) 5 September 19th 05 06:59 PM


All times are GMT +1. The time now is 04:02 PM.

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

About Us

"It's about Microsoft Excel"