drawing a line with VBA

plost33

Well-known Member
Joined
Oct 2, 2008
Messages
866
How would i have VBA draw a line between a two ranges? say i have a named range of "start" and another name range "stop". i want to draw a red line between them. how can i do that with code. this is beggining my education for a much larger project I want to do later in the future.
 
Try forcing a refresh after drawing the first line:

Code:
Application.ScreenUpdating = True
Application.Wait Now + TimeSerial(0, 0, 1)
 
Upvote 0

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
VOG IS THERE A CODE that can clear all lines from a sheet? not all objects because i have a button on the sheet. i just wanna remove all lines.
 
Upvote 0
This worked for me (Excel 2007)

Code:
Sub ClrLine()
Dim ln As Shape
For Each ln In ActiveSheet.Shapes
    If ln.Name Like "*Connector*" Then ln.Delete
Next ln
End Sub
 
Upvote 0
Try

Code:
Sub AddLine()
Dim l1 As Long, l2 As Long, r1 As Long, r2 As Long
l1 = Range("Start").Left
l2 = Range("Start").Top
r1 = Range("Stop").Left
r2 = Range("Stop").Top
With ActiveSheet.Shapes.AddLine(l1, l2, r1, r2).Line
    .ForeColor.RGB = RGB(255, 0, 0)
End With
End Sub
[

hi, first of all, i'm new to vba. and i would like to ask, how do i run this code after i've pasted it into the vba module?
 
Upvote 0

Forum statistics

Threads
1,223,247
Messages
6,171,004
Members
452,374
Latest member
keccles

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