red box around selection cells

lezawang

Well-known Member
Joined
Mar 27, 2016
Messages
1,805
Office Version
  1. 2016
Platform
  1. Windows
Hi
I came cross this website/code which I found it a bit difficult to understand. The author said he got help from this forum to learn vba; so I figured, then it must be better/easier coding than this to do the same from someone from here. i would appreciate any help. Thanks a lot.

Rich (BB code):
[FONT=&quot]Sub[/FONT][FONT=&quot] RedBox()[/FONT]
[FONT=&quot]'PURPOSE: Create a Red Box to Highlight Cell Selection[/FONT]
[FONT=&quot]'SOURCE: www.TheSpreadsheetGuru.com[/FONT]

[FONT=&quot]Dim[/FONT][FONT=&quot] Box [/FONT][FONT=&quot]As[/FONT][FONT=&quot] Shape[/FONT]

[FONT=&quot]'Create a Red Box based on Cell Selection[/FONT]
[FONT=&quot]  [/FONT][FONT=&quot]On[/FONT][FONT=&quot] [/FONT][FONT=&quot]Error[/FONT][FONT=&quot] [/FONT][FONT=&quot]GoTo[/FONT][FONT=&quot] Select_Cell:[/FONT]
[FONT=&quot]    [/FONT][FONT=&quot]Set[/FONT][FONT=&quot] Box = ActiveSheet.Shapes.AddShape( _[/FONT]
[FONT=&quot]      Type:=msoShapeRectangle, _[/FONT]
[FONT=&quot]      Left:=Selection.Left, _[/FONT]
[FONT=&quot]      Top:=Selection.Top, _[/FONT]
[FONT=&quot]      Width:=Selection.Width, _[/FONT]
[FONT=&quot]      Height:=Selection.Height)[/FONT]
[FONT=&quot]  [/FONT][FONT=&quot]On[/FONT][FONT=&quot] [/FONT][FONT=&quot]Error[/FONT][FONT=&quot] [/FONT][FONT=&quot]GoTo[/FONT][FONT=&quot] 0[/FONT]

[FONT=&quot]'Rename Box with Tag[/FONT]
[FONT=&quot]  Box.Name = Box.Name & "_RedBox"[/FONT]

[FONT=&quot]'Format the Red Box[/FONT]
[FONT=&quot]  Box.Fill.Visible = msoFalse[/FONT]
[FONT=&quot]  Box.Line.Visible = msoTrue[/FONT]
[FONT=&quot]  Box.Line.ForeColor.RGB = RGB(255, 0, 0)[/FONT]
[FONT=&quot]  Box.Line.Weight = 2.25[/FONT]

[FONT=&quot]Exit[/FONT][FONT=&quot] [/FONT][FONT=&quot]Sub[/FONT]

[FONT=&quot]'ERROR HANDLER[/FONT]
[FONT=&quot]Select_Cell:[/FONT]
[FONT=&quot]  MsgBox "Select a cell in order to use this button."[/FONT]
[FONT=&quot]    [/FONT]
[FONT=&quot]End[/FONT][FONT=&quot] [/FONT][FONT=&quot]Sub


[/FONT]
https://www.thespreadsheetguru.com/blog/how-to-keep-track-of-your-shapes-created-with-vba-code[FONT=&quot]

[/FONT]
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
Thanks for your reply. I basically want to do the same thing. put a red box around the selected cells. I would appreciate help to understand the code above or simpler version of that code. Thank you once again for all your help before and now.
 
Upvote 0
When you say Box do you mean Border

And how do you want this script activated?

Do you mean any time you select a cell you want a border around that cell.

And then the border removed if you select a new cell and then that new cell have a border

And what color do you want this border?

See I need specific details like this
 
Upvote 0
Me looking at that code does not look so long.
Depending on what you want.

If it meets you needs why does it need to be shorter?
What part do you not like?
 
Upvote 0

Forum statistics

Threads
1,214,826
Messages
6,121,794
Members
449,048
Latest member
greyangel23

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