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.
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
Hello,

I'm testing out the above code and getting this error: Run-time error '1004': Method 'Range' of object '_Global' failed

Am i not setting the Range correctly?

Thank you,
Karen
 
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
[
Hey Vog

i am looking for a vba code that would check if any of my cell contents have alphanumeric data in the form “A1010” and return a value “E1017” in the cell below i.e. adding 7 to the numbers and switching “A” to “E” in the cell below.

subsequently it must insert a straight line below the “E1017” cell downwards

Trying to create a project for an internal logistic process.

Would really appreciate your help :)

Best regards

fairin
 
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
[
Hey Vog

i am looking for a vba code that would check if any of my cell contents have alphanumeric data in the form “A1010” and return a value “E1017” in the cell below i.e. adding 7 to the numbers and switching “A” to “E” in the cell below.

subsequently it must insert a straight line below the “E1017” cell pointing towards the next “A1
Trying to create a project for an internal logistic process.

Would really appreciate your help :)

Best regards
 
Upvote 0
I've only come here and logged on to compliment VoG on being so patient and helpful to all the folks in this thread. I read the whole thread purely out of entertainment and VoG you were a kind person all the way through.
 
Upvote 0

Forum statistics

Threads
1,223,247
Messages
6,171,007
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