Vertically center comment in cell

Pinball

Board Regular
Joined
Apr 18, 2002
Messages
107
Is there code I can add to the following that will vertically center the comment? Actually I would like the comment vertically centered in the cell located to the immediate right of the active cell (cell G2 in this case). I don't want the comment sized to fit the row height, just to be centered vertically within the existing row height.

Sub test()
Range("F2").Activate
ActiveCell.ClearComments
ActiveCell.AddComment
ActiveCell.Comment.Visible = True
ActiveCell.Comment.Shape.Select
With Selection
.ShapeRange.ScaleHeight 0.2, msoFalse, msoScaleFromTopLeft
.ShapeRange.ScaleWidth 0.8, msoFalse, msoScaleFromTopLeft
.ShapeRange.Fill.ForeColor.SchemeColor = 22
.ShapeRange.IncrementLeft -7.25
End With
ActiveCell.Comment.Text Text:="this is a test"
With ActiveCell.Comment.Shape.TextFrame.Characters.Font
.Bold = True
.ColorIndex = 5
End With
Range("F2").Activate
End Sub
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
Pinball

Try this:

Sub test()
Range("F2").Activate
ActiveCell.ClearComments
ActiveCell.AddComment
ActiveCell.Comment.Visible = True
ActiveCell.Comment.Shape.Select
With Selection
.ShapeRange.ScaleHeight 0.2, msoFalse, msoScaleFromTopLeft
.ShapeRange.ScaleWidth 0.8, msoFalse, msoScaleFromTopLeft
.ShapeRange.Fill.ForeColor.SchemeColor = 22
.ShapeRange.IncrementLeft -7.25
If .ShapeRange.Height <= Rows(2).Height Then
.ShapeRange.Top = Rows(2).Top + (Rows(2).Height - .ShapeRange.Height) / 2
Else
.ShapeRange.Top = Rows(2).Top - (.ShapeRange.Height - Rows(2).Height) / 2
End If
End With
ActiveCell.Comment.Text Text:="this is a test"
With ActiveCell.Comment.Shape.TextFrame.Characters.Font
.Bold = True
.ColorIndex = 5
End With
Range("F2").Activate
End Sub

If you wanted, you could set variables, but this should give you the general idea.

Any help?

Regards

Robb__
 
Upvote 0

Forum statistics

Threads
1,213,546
Messages
6,114,256
Members
448,558
Latest member
aivin

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