• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Duplicate VBA code

Hello,
I have a file that marks the place where a car is damaged.
Now when the first schape is already used i would like that i can use a second schape to mark a second place where the car is damaged, but i can not find out how.
Thanks in advance
File included
When you click a name in O it puts a mark on that place where the care is damaged
 

Attachments

  • Schade.xlsb
    45.1 KB · Views: 4
Hi,

Is this what you are looking for?

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)

Check1:
With ActiveSheet.Shapes.Range(Array("Schade1"))
    If Not Intersect(Target, Range("O2:O20")) Is Nothing Then
            .Visible = True
            .Left = ActiveCell.Offset(0, 1)
            .Top = ActiveCell.Offset(0, 2)
        Else
        .Visible = True
        End If
End With

Check2:
With ActiveSheet.Shapes.Range(Array("Schade2"))
    If Not Intersect(Target, Range("S2:S20")) Is Nothing Then
            .Visible = True
            .Left = ActiveCell.Offset(0, 1)
            .Top = ActiveCell.Offset(0, 2)
        Else
        .Visible = True
        End If
End With

End Sub
 

Attachments

  • Schade.xlsm
    46.4 KB · Views: 4
Last edited:
Hello Villa lobos,
Thank you for such fast reply, great!
This is exactly what i was looking for.
I have one more question is it possible when I choose M2 or M3 shape 1 or shape 2 is not vissible anymore?
Thanks again
 
maybe try this... if you click in cell M2 or M3 the "Schade2" is invisible

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)

Check1:
With ActiveSheet.Shapes.Range(Array("Schade1"))
    If Not Intersect(Target, Range("O2:O20")) Is Nothing Then
            .Visible = True
            .Left = ActiveCell.Offset(0, 1)
            .Top = ActiveCell.Offset(0, 2)
        Else
        .Visible = True
        End If
End With

Check2:
With ActiveSheet.Shapes.Range(Array("Schade2"))
    If Not Intersect(Target, Range("S2:S20")) Is Nothing Then
            .Visible = True
            .Left = ActiveCell.Offset(0, 1)
            .Top = ActiveCell.Offset(0, 2)
        ElseIf Not Intersect(Target, Range("M2:M3")) Is Nothing Then
            .Visible = False
        Else
        .Visible = True
        End If
End With

End Sub
 
Hello,
Thank you again
This part
Code:
 ElseIf Not Intersect(Target, Range("M2:M3")) Is Nothing Then.Visible = False
works great
Last question:
Is there a way to eleminate this
or if you click in O9 or S9 the Schade1 or Schade2 "jump" to A1
than it would be perfect
 
hello,
Sorry, I do not understand , in your first code the first shape also jumps to A1
I mean
Is it possible that nothing happens with the shapes when i am out of the list
2 possible ways: Or they are on the car or they are not visible
Thank you for your patience
 
Back
Top