aligning textboxes on worksheet by cell reference?

D

dreamz

how can i code in vba xy positions of textboxes on a worksheet according
to a cell reference?

e.g. textbox1 is aligned with cell a1, textbox2 is aligned with cell
c1, etc.

thanks.
 
K

K Dales

Public Sub FitObjectToRange(MyObject As Object, MyLocation As Range)

MyObject.Top = MyLocation.Top
MyObject.Left = MyLocation.Left
MyObject.Width = MyLocation.Width
MyObject.Height = MyLocation.Height

End Sub

Example of use:
FitObjectToRange ActiveSheet.TextBox1, Range("A1")
FitObjectToRange ActiveSheet.TextBox2, Range("C1")

MyObject can be any object that has a .top, .left, .width, and .height (e.g.
commandbuttons, images, ...)
MyLocation can be a cell or a range of cells
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top