point and selection

newapa

Board Regular
Joined
Sep 13, 2012
Messages
69
Hi!
I'm trying to make that if the point is selected the label will show.
but it's not working. the object doesn't work.

it work when i have set spoint = selection.
but if i have it like that i will get type missmatch all the time.

Code:
sub test()
dim ch as chart
dim spoint as point
label1.visible = false

set ch = activechart.parent

if sPoint = Selection then
    label1.visible = true


    With Label1
        .Left = ch.Chart.PlotArea.Left
        .Top = ch.Chart.PlotArea.Top
        .Height = 20
        .Width = 20
    End With
end if
end sub

thx in advance
 
Last edited:

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
Hi andrew!

i got one more question. how can i check if the chart is selected. just now if i'm not select any chart it will complain.
i tryied it like this. but it doesn't work

if ch is nothing then
exit sub
else
do other code here.
end if
 
Last edited:
Upvote 0
i have tryied it and it doesn't work.

here the code

Code:
Dim sPoint As Point
    Dim ch As ChartObject
    Dim BtwTop As Long
    Dim BtwLeft As Long
       
    Set ch = ActiveChart.Parent
 
    Label1.Visible = False
   
    BtwTop = ch.Top + ch.Chart.PlotArea.Top
    BtwLeft = ch.Left + ch.Chart.PlotArea.Left
   
    If TypeName(Selection) = "Point" Then
       
        If ch Is Nothing Then
            MsgBox "hej då"
            Exit Sub
        Else
       
            With Label1
                .Visible = True
                .BringToFront
                .Left = BtwLeft
                .Top = BtwTop
                .Height = ch.Chart.PlotArea.Height
                .Width = ch.Chart.PlotArea.Width
            End With
        End If
    End If
 
Upvote 0
You didn't do what I said. Try:

Code:
Sub test()
    Dim ch As ChartObject
    Dim BtwTop As Long
    Dim BtwLeft As Long
    If TypeName(Selection) = "Point" Then
        Set ch = ActiveChart.Parent
        Label1.Visible = False
        BtwTop = ch.Top + ch.Chart.PlotArea.Top
        BtwLeft = ch.Left + ch.Chart.PlotArea.Left
        With Label1
            .Visible = True
            .BringToFront
            .Left = BtwLeft
            .Top = BtwTop
            .Height = ch.Chart.PlotArea.Height
            .Width = ch.Chart.PlotArea.Width
        End With
    End If
End Sub
 
Upvote 0
ohhh sorry!
i miss understod it. so i put the if ch is nothing in there insted of moving it.

thx agian andrew
big thx
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,231
Messages
6,170,884
Members
452,364
Latest member
springate

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