Draw line in a specific cell and change font color

imageicb

Board Regular
Joined
Jan 13, 2012
Messages
66
I have a button that when you click it it inserts a line via the below code:

Sub test()
ActiveSheet.Shapes.AddLine(100, 300#, 300, 300).Select
End Sub

How can I tell it to draw the line in a specific cell (AM13, P15,ect.). Also I would like it to turn the font of any data in the cells that ar lined out white.

Is it also possible that upon another click it will remove the line and return the font to black.

Any help would be great,

Thanks
 
ok i added as follows:

Sub removet()
Range("line").Select
On Error Resume Next
For Each cll In Selection.Cells
cll.Font.ColorIndex = xlAutomatic
For Each shp In ActiveSheet.Shapes
If shp.Type = msoLine And shp.TopLeftCell.Address = cll.Address Then shp.Delete
Next shp
Next cll
End Sub

The addition of the On Error Resume Next allowed it to compete but upon completion all of my drop downs (from data validation) were removed.
 
Upvote 0

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
Data Validation arrows are shapes but don't have a topleftcell property, so I split the .type and .topleftcell question:
Code:
Sub test3()
For Each cll In Selection.Cells
  cll.Font.ColorIndex = xlAutomatic
  For Each shp In ActiveSheet.Shapes
    If shp.Type = msoLine Then
      If shp.TopLeftCell.Address = cll.Address Then shp.Delete
    End If
  Next shp
Next cll
End Sub
 
Upvote 0

Forum statistics

Threads
1,216,372
Messages
6,130,223
Members
449,567
Latest member
ashsweety

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