Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 275
Default VB code to check number in Rectangle box

Hi,

I am working on a worksheet that contains 20 Rectange boxes created by the
user.

Is there a way using VB to check the number (which falls between 1 and 21)
in a seperate Rectangle box - say Rectangle 50
then plot each seperate Rectangle box numbers 1-20 with the numbers 1-20
excluding the number found in Rectangle box50

eg - Rectangle box50 contains number 3

VB code will put
number 1 in Rectangle box 1
number 2 in Rectangle box 2
number 4 in Rectangle box 3
etc
etc

hope this makes sense?
thanks
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 39
Default VB code to check number in Rectangle box

Hello,
I've attached some code that does what you are asking for (at least,
it does what I think you're asking for).
When you said "Rectangle boxes" you are referring to the rectangle
shapes (from the drawing toolbar), which have text in them, correct?
You don't just mean some box which happens to have a rectangular
shape? (sorry if this is confusing). The reason I ask is because this
macro will work for the rectangle shapes from the Drawing toolbar
ONLY. If those 'rectangular boxes' are actually textboxes (which are
rectangular, but not rectangle shapes (as far as Excel is concerned)),
then this macro will not work (although it could be easily modified to
check textboxes).
I apologize if you already knew the distinction, I just wanted to be
clear what the original question was.
I hope this helps.


Sub Rectangular_boxes()
'Response to:
'http://groups.google.com/group/microsoft.public.excel.programming/
browse_thread/thread/b1edd828c4fa2226/#
'This code works with Rectangles, NOT textboxes
Dim shp As Shape
Dim strShpName As String
Dim shpBoxToCheck As Shape
Dim strBoxToCheck As String
Dim iBoxNumber As Integer
Dim iShapeNumber As Integer

'Which box are we going to get the number out of (in your example, you
said "Rectangle 50")
'If this is going to be the same all the time, you can just use the
following line of code
'strBoxToCheck = "50"
strBoxToCheck = InputBox(Prompt:="Please select the number of the box
that you want to read a value from")
'Loop through all of the shapes in the activesheet
For Each shp In ActiveSheet.Shapes
'Look only at the rectange shapes
If shp.Type = msoAutoShape And shp.AutoShapeType =
msoShapeRectangle Then
'remove "Rectange " from the name so we can see what the
number is
If Replace(shp.Name, "Rectangle ", vbNullString) =
strBoxToCheck Then
Set shpBoxToCheck = shp
'select the shape so we can read the text
'I might be missing some .text or .value property for the
shape
'If there is some property that will let you read the
value without
'selecting the shape, the code will run slightly faster
(and look nicer)
shp.Select
'In case the name can't be converted to an integer, the
macro will exit
On Error Resume Next
iBoxNumber = CInt(Selection.Characters.Text)
If Err.Number < 0 Then Exit Sub
On Error GoTo 0
End If
End If
Next shp
'Loop through all of the shapes again
For Each shp In ActiveSheet.Shapes
If shp.Type = msoAutoShape And shp.AutoShapeType =
msoShapeRectangle Then
iShapeNumber = CInt(Replace(shp.Name, "Rectangle ",
vbNullString))
Select Case iShapeNumber
'If iBoxNumber is 5 and shp refers to "Rectange 4", "4" will
be left in the text area
Case Is < iBoxNumber
shp.Select
Selection.Characters.Text = iShapeNumber
'If iBoxNumber is 5 and shp refers to "Rectange 7", "8" will
be left in the text area
Case Is = iBoxNumber
shp.Select
Selection.Characters.Text = iShapeNumber + 1
End Select
End If
Next shp
End Sub
On Mar 8, 3:28 pm, Anthony wrote:
Hi,

I am working on a worksheet that contains 20 Rectange boxes created by the
user.

Is there a way using VB to check the number (which falls between 1 and 21)
in a seperate Rectangle box - say Rectangle 50
then plot each seperate Rectangle box numbers 1-20 with the numbers 1-20
excluding the number found in Rectangle box50

eg - Rectangle box50 contains number 3

VB code will put
number 1 in Rectangle box 1
number 2 in Rectangle box 2
number 4 in Rectangle box 3
etc
etc

hope this makes sense?
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
Code to get a Range RECTangle or PT keepITcool Excel Programming 6 August 12th 05 06:54 PM
Just a code check please... ste mac Excel Programming 9 March 21st 05 09:29 AM
Name Check Box in code Paul Excel Programming 4 December 5th 04 03:09 PM
Values of Rectangle or Check box Mountain Bikers Excel Programming 2 May 19th 04 01:05 PM
Check Box Code Bob Excel Programming 3 January 14th 04 06:07 AM


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