Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 295
Default Snap an object to a cell border via macro

Hello there

I want to move a text box to the corner of a cell (say "Textbox 1" to the
corner of Cell A1) by using a macro. I can't find anything in help or the
threads in Discussion forums. I tried recording a macro and turning on the
"snap to grid" tool as the first step, but it didn't generate any code. Does
anyone have a solution please?

Regards, Brett
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 747
Default Snap an object to a cell border via macro

Try:

With ActiveSheet.Shapes("Text Box 1")
.Left = Range("A1").Left
.Top = Range("A1").Top
End With

Greg
  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 295
Default Snap an object to a cell border via macro

Absolute corker! Thanks Greg - you don't know how much that will change my
life!
Regards, Brett

"Greg Wilson" wrote:

Try:

With ActiveSheet.Shapes("Text Box 1")
.Left = Range("A1").Left
.Top = Range("A1").Top
End With

Greg

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 295
Default Snap an object to a cell border via macro

Hi Greg, I was just fooling around with that and tried

.right = Range("A1").right
.bottom = Range("A1").bottom


(pretty obvious, really) and it debugs. When I typed the right in lower case
it auto-corrected it, so I thought that it might work, but it doesn't like
Right or Bottom it seems. Any clues?
Brett


"Greg Wilson" wrote:

Try:

With ActiveSheet.Shapes("Text Box 1")
.Left = Range("A1").Left
.Top = Range("A1").Top
End With

Greg

  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 747
Default Snap an object to a cell border via macro

Right and Bottom are properties that just aren't supported by the VBA Shapes
collection. Generally, Right and Bottom are achieved by adding the Width
property to the Left property and the Height property to the Top property
respectively.

Greg



"Brettjg" wrote:

Hi Greg, I was just fooling around with that and tried

.right = Range("A1").right
.bottom = Range("A1").bottom


(pretty obvious, really) and it debugs. When I typed the right in lower case
it auto-corrected it, so I thought that it might work, but it doesn't like
Right or Bottom it seems. Any clues?
Brett


"Greg Wilson" wrote:

Try:

With ActiveSheet.Shapes("Text Box 1")
.Left = Range("A1").Left
.Top = Range("A1").Top
End With

Greg



  #6   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 295
Default Snap an object to a cell border via macro

Ok thanks, I'll research those properties.

"Greg Wilson" wrote:

Right and Bottom are properties that just aren't supported by the VBA Shapes
collection. Generally, Right and Bottom are achieved by adding the Width
property to the Left property and the Height property to the Top property
respectively.

Greg



"Brettjg" wrote:

Hi Greg, I was just fooling around with that and tried

.right = Range("A1").right
.bottom = Range("A1").bottom


(pretty obvious, really) and it debugs. When I typed the right in lower case
it auto-corrected it, so I thought that it might work, but it doesn't like
Right or Bottom it seems. Any clues?
Brett


"Greg Wilson" wrote:

Try:

With ActiveSheet.Shapes("Text Box 1")
.Left = Range("A1").Left
.Top = Range("A1").Top
End With

Greg

  #7   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Snap an object to a cell border via macro

Just in case you have trouble:

With ActiveSheet.Shapes("Text Box 1")
.Left = .Parent.Range("A1").Left
.Top = .Parent.Range("A1").Top
.Width = .Parent.Range("a1").Width
.Height = .Parent.Range("a1").Height
End With

I like to qualify my ranges, so I can use:

With worksheets("sheet9999").Shapes("Text Box 1")
.Left = .Parent.Range("A1").Left
.Top = .Parent.Range("A1").Top
.Width = .Parent.Range("a1").Width
.Height = .Parent.Range("a1").Height
End With


Brettjg wrote:

Ok thanks, I'll research those properties.

"Greg Wilson" wrote:

Right and Bottom are properties that just aren't supported by the VBA Shapes
collection. Generally, Right and Bottom are achieved by adding the Width
property to the Left property and the Height property to the Top property
respectively.

Greg



"Brettjg" wrote:

Hi Greg, I was just fooling around with that and tried

.right = Range("A1").right
.bottom = Range("A1").bottom

(pretty obvious, really) and it debugs. When I typed the right in lower case
it auto-corrected it, so I thought that it might work, but it doesn't like
Right or Bottom it seems. Any clues?
Brett


"Greg Wilson" wrote:

Try:

With ActiveSheet.Shapes("Text Box 1")
.Left = Range("A1").Left
.Top = Range("A1").Top
End With

Greg


--

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
Place a Bottom Border in a Table via a Macro [email protected] Excel Discussion (Misc queries) 0 February 25th 07 11:19 PM
Macro to Create New Worksheet and Reference Cell in Old Worksheet As Tab Name - "Object Required" Error [email protected] Excel Discussion (Misc queries) 4 September 25th 06 01:35 PM
Macro linked to text or an object areaume Excel Discussion (Misc queries) 1 May 15th 06 08:15 PM
Very interesting problem that should be a snap to figure out! KenRamoska Excel Discussion (Misc queries) 3 March 15th 06 08:38 PM
Changing the border of one cell s/n change the border of adjacent gjanssenmn Excel Discussion (Misc queries) 2 October 5th 05 08:35 PM


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