#1   Report Post  
Junior Member
 
Location: USA
Posts: 3
Unhappy Help Needed

Good evening,

I would like to create a table in Excel, for simplicity, let’s say 4x4. The table could occupy cells D4:G8. The cells would be numbered 1 thru 16. What I am trying to accomplish is using VBA whenever any of the cells are selected the selected number would appear in another cell, let’s say A2, just like it appears in the formula bar. This may not be far too difficult to solve because no one has been able to code it and I must confess that don't have a clue where to start.

Anyway, thanks for anyone’s help to try and solve the code.

noway
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 538
Default Help Needed

noway wrote:

I would like to create a table in Excel, for simplicity, let’s say 4x4.
The table could occupy cells D4:G8. The cells would be numbered 1 thru
16. What I am trying to accomplish is using VBA whenever any of the
cells are selected the selected number would appear in another cell,
let’s say A2, just like it appears in the formula bar. This may not be
far too difficult to solve because no one has been able to code it and I
must confess that don't have a clue where to start.

Anyway, thanks for anyone’s help to try and solve the code.


Put this in the sheet's class in the VBA editor:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Const TOPROW = 4
Const BOTTOMROW = 8
Const LEFTCOL = 4
Const RIGHTCOL = 7
Select Case Target.Row
Case TOPROW To BOTTOMROW
Select Case Target.Column
Case LEFTCOL To RIGHTCOL
Range("A2").Value = ((Target.Row - TOPROW) * _
(RIGHTCOL - LEFTCOL + 1)) + _
Target.Column - LEFTCOL + 1
End Select
End Select
End Sub

Note that using D4:G8 results in a grid of 20 cells, not 16. Adjust the above
constants as desired. (For a grid of 16 cells, set BOTTOMROW = 7.)

Now give me a hard one!

--
I have known few men who were noble,
for nobility is scarcer far than heroism.
  #3   Report Post  
Junior Member
 
Location: USA
Posts: 3
Default

Quote:
Originally Posted by Auric__ View Post
noway wrote:

I would like to create a table in Excel, for simplicity, let’s say 4x4.
The table could occupy cells D4:G8. The cells would be numbered 1 thru
16. What I am trying to accomplish is using VBA whenever any of the
cells are selected the selected number would appear in another cell,
let’s say A2, just like it appears in the formula bar. This may not be
far too difficult to solve because no one has been able to code it and I
must confess that don't have a clue where to start.

Anyway, thanks for anyone’s help to try and solve the code.


Put this in the sheet's class in the VBA editor:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Const TOPROW = 4
Const BOTTOMROW = 8
Const LEFTCOL = 4
Const RIGHTCOL = 7
Select Case Target.Row
Case TOPROW To BOTTOMROW
Select Case Target.Column
Case LEFTCOL To RIGHTCOL
Range("A2").Value = ((Target.Row - TOPROW) * _
(RIGHTCOL - LEFTCOL + 1)) + _
Target.Column - LEFTCOL + 1
End Select
End Select
End Sub

Note that using D4:G8 results in a grid of 20 cells, not 16. Adjust the above
constants as desired. (For a grid of 16 cells, set BOTTOMROW = 7.)

Now give me a hard one!

--
I have known few men who were noble,
for nobility is scarcer far than heroism.
Excellent, it worked just as you said and Thanks a Million.
  #4   Report Post  
Junior Member
 
Location: USA
Posts: 3
Default

Quote:
Originally Posted by noway View Post
Excellent, it worked just as you said and Thanks a Million.
Auric,

I have hit a snag. The numbers in my table are not consecutive.
They are like the following with several more as the table is larger.

48 43 4 8
34 12 20 1
40 16 18 23
17 11 50 19

Having odd numbers may be where the difficulty lies. Any hope for this arrangement?

Thanks,
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
Help Needed Benji Excel Discussion (Misc queries) 3 September 30th 09 06:36 PM
CSV Help needed LostInNY Excel Programming 4 July 8th 09 12:46 AM
Deleting Rows With Non-Needed Data between Needed Data Daren Excel Worksheet Functions 2 September 30th 08 06:47 PM
Help Needed? Nad Excel Discussion (Misc queries) 1 April 24th 07 12:02 PM
help needed cward1 Excel Worksheet Functions 1 September 28th 06 01:47 PM


All times are GMT +1. The time now is 10:19 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"