Need help to move the point of two lines created by VBA

Tirrazo

New Member
Joined
May 19, 2022
Messages
19
Office Version
  1. 365
Platform
  1. Windows
Hi,

Is it possible to edit this code so that the lines will meet each other on the left side, not the right side?

Is it also possible to make a code for just the bottom line?


Regards


VBA Code:
Option Explicit

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    On Error Resume Next
    If Not Intersect(Target, Range("A1:CF300")) Is Nothing Then ' < this is the range where you want the lines to be
        With ActiveSheet.Shapes("Down Arrow 1")
            .Visible = True ' make the line visible
            .Left = Target.Left + Target.Width
            .Top = 0 ' very top of worksheet
            .Width = 3 ' width of line
            .Height = Rows("1:" & Target.Row).Height
        End With
        With ActiveSheet.Shapes("Right Arrow 1")
            .Visible = True ' make the line visible
            .Left = 0 ' very left of worksheet
            .Top = Target.Top + Target.Height
            .Width = Range(Cells(Target.Row, 1), Cells(Target.Row, Target.Column)).Width
            .Height = 3 ' width of the line
        End With
    Else
        ActiveSheet.Shapes("Down Arrow 1").Visible = False ' hide the lines if out of range
        ActiveSheet.Shapes("Right Arrow 1").Visible = False ' hide the lines if out of range
    End If
    On Error GoTo 0
End Sub
 

Attachments

  • Lines meet left bottom.PNG
    Lines meet left bottom.PNG
    4.8 KB · Views: 3
  • Line bottom.PNG
    Line bottom.PNG
    4.1 KB · Views: 4

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
How about
VBA Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    On Error Resume Next
    If Not Intersect(Target, Range("A1:CF300")) Is Nothing Then ' < this is the range where you want the lines to be
        With ActiveSheet.Shapes("Down Arrow 1")
            .Visible = True ' make the line visible
            .Left = Target.Left
            .Top = 0 ' very top of worksheet
            .Width = 3 ' width of line
            .Height = Rows("1:" & Target.Row).Height
        End With
        With ActiveSheet.Shapes("Right Arrow 1")
            .Visible = True ' make the line visible
            .Left = 0 ' very left of worksheet
            .Top = Target.Top + Target.Height
            .Width = Range(Cells(Target.Row, 1), Cells(Target.Row, Target.Column - 1)).Width
            .Height = 3 ' width of the line
        End With
    Else
        ActiveSheet.Shapes("Down Arrow 1").Visible = False ' hide the lines if out of range
        ActiveSheet.Shapes("Right Arrow 1").Visible = False ' hide the lines if out of range
    End If
    On Error GoTo 0
End Sub
 
Upvote 0
Thank you! :)

This is working very well!

Is it possible to extend the horizontal line beyond the marked cell x cells to the right from the cell you are standing on?
 
Upvote 0
Yes, just change the -1 to + whatever you want.
 
Upvote 0
This is working, but now there is another issue.

As the horizontal line is passing beyond the cell, I can't drag the cell because the line lies above.

Is there any solution to this or is the solution to put the line on top of the cell instead of under?
 

Attachments

  • Cant drag the cell.PNG
    Cant drag the cell.PNG
    6.7 KB · Views: 3
Upvote 0
You could shift it up a bit like
VBA Code:
            .Top = Target.Top + Target.Height / 2
 
Upvote 0
That is working to.

What number do you divide with to get the line on top of the cell?
 
Upvote 0
Try
VBA Code:
.Top = Target.Top
 
Upvote 0

Forum statistics

Threads
1,215,214
Messages
6,123,664
Members
449,114
Latest member
aides

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