Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Making a connection: shape clicked and cell it lies over.

Hi,
I'm a relative newcomer to VB, but I'm stuck on the following problem:
I have a 10 x 10 multiplaction square, than when each square is clicked
on, the font changes colour, and the answer appears. To assign the macro
though, I created 100 autoshape rectangles and lined them up over my
10x10 squares, then used code such as:

Sub Rectangle1_Click()
Range("B2").Select
Call Color_Change
End Sub

Sub Rectangle2_Click()
Range("C2").Select
Call Color_Change
End Sub

Sub Rectangle3_Click()
Range("D2").Select
Call Color_Change
End Sub
....
Sub Color_Change()
cell(va, va).Select
col = Selection.Font.ColorIndex
If col = 1 Then
Selection.Font.ColorIndex = 2
Else
Selection.Font.ColorIndex = 1
End If
End Sub

Now the range().select is hard-coded into each sub (giving a lot of
subs), and I can't work out how to get a connection between the shape
that was clicked (even by using topleftcell.address) and the cell I need
to change the font in. Surely there's a neater way of doing what I've
got?

Thanks
--
Gazza
"I was asked to put on a clean pair of socks everyday. By the end of the
week, I couldn't get my shoes on."
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Making a connection: shape clicked and cell it lies over.

Assign the following to all you rectangles. (assuming the are objects of
type rectangle).

Sub AnyRectangle_Click()
dim r as Rectangle
dim rng as Range, col as Long
set r = activesheet.Rectangles(application.Caller)
set rng = r.topLeftCell
col = rng.Font.ColorIndex
If col = 1 Then
rng.Font.ColorIndex = 2
Else
rng.Font.ColorIndex = 1
End If
End Sub


--
Regards,
Tom Ogilvy


Gazza wrote in message
. com...
Hi,
I'm a relative newcomer to VB, but I'm stuck on the following problem:
I have a 10 x 10 multiplaction square, than when each square is clicked
on, the font changes colour, and the answer appears. To assign the macro
though, I created 100 autoshape rectangles and lined them up over my
10x10 squares, then used code such as:

Sub Rectangle1_Click()
Range("B2").Select
Call Color_Change
End Sub

Sub Rectangle2_Click()
Range("C2").Select
Call Color_Change
End Sub

Sub Rectangle3_Click()
Range("D2").Select
Call Color_Change
End Sub
...
Sub Color_Change()
cell(va, va).Select
col = Selection.Font.ColorIndex
If col = 1 Then
Selection.Font.ColorIndex = 2
Else
Selection.Font.ColorIndex = 1
End If
End Sub

Now the range().select is hard-coded into each sub (giving a lot of
subs), and I can't work out how to get a connection between the shape
that was clicked (even by using topleftcell.address) and the cell I need
to change the font in. Surely there's a neater way of doing what I've
got?

Thanks
--
Gazza
"I was asked to put on a clean pair of socks everyday. By the end of the
week, I couldn't get my shoes on."



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Making a connection: shape clicked and cell it lies over.

Hi

I have a similar problem- I have images(GIFs) on my Excel worksheet with macros assigned to. I want to forward a value to the macro according to the image that was clicked (the name of the image or The TopLeft.Cell.Name). My experience was not enough to successfully modify the macro below though. Can anyone help me out

----- Tom Ogilvy wrote: ----

Assign the following to all you rectangles. (assuming the are objects o
type rectangle)

Sub AnyRectangle_Click(
dim r as Rectangl
dim rng as Range, col as Lon
set r = activesheet.Rectangles(application.Caller
set rng = r.topLeftCel
col = rng.Font.ColorInde
If col = 1 The
rng.Font.ColorIndex =
Els
rng.Font.ColorIndex =
End I
End Su


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
Function Arguments dialog vanishes when clicked an inserted shape RK Excel Worksheet Functions 2 February 2nd 09 07:58 AM
enter time when shape is clicked Dgwood90 Excel Discussion (Misc queries) 1 October 15th 08 10:31 AM
How do I add connection sites to a shape Dick Herlein Excel Discussion (Misc queries) 1 May 20th 06 04:25 PM
How to tell wich object/shape was clicked Andrew Ofthesong Excel Programming 2 December 1st 03 05:05 PM
detecting shape clicked on notsureofthatinfo Excel Programming 1 October 15th 03 07:46 AM


All times are GMT +1. The time now is 04:28 AM.

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"