VBA to move lable to a specific range in a work sheet

CEO76

New Member
Joined
Jun 25, 2007
Messages
8
Hi all,

I have one ActiveX control Label inserted into a worksheet. There is a particular range on that work sheet I would like to resize the lable to the range height and width as well as move the lable to cover the range.

I can code to size the lable, however, I don't know how to move the lable to cover the range on that worksheet.

Could any of you help me with a vba code to perform the label move?

Thanks

CEO76
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
Try like this

Code:
Sub test()
With ActiveSheet.OLEObjects("Label1")
    .Top = Range("C5").Top
    .Left = Range("C5").Left
End With
End Sub
 
Upvote 0
Does this code do what you want (just change my example sheet and range to your actual sheet and range and, of course, use your label's actual name)...

Code:
Sub MoveResizeLabel()
  Dim RangeToCover As Range
  Set RangeToCover = Range("D4:G9")
  With Worksheets("Sheet1").Label1
    .Left = RangeToCover.Left
    .Top = RangeToCover.Top
    .Width = RangeToCover.Width
    .Height = RangeToCover.Height
  End With
End Sub
 
Last edited:
Upvote 0
Hi Rick & Vog,

The code works great. This is what I reall want.

I want to have an event whrere I move my mouse over a range and a cell in that range highlighted. The only way to do it is to have a mouseover event on the labale.

Anyway. I reall appreciate your help on moving the label to a specific range.

Cheers
 
Upvote 0

Forum statistics

Threads
1,224,592
Messages
6,179,789
Members
452,942
Latest member
VijayNewtoExcel

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top