Macro not working (Hover Chart)

kbriaz

Board Regular
Joined
Dec 5, 2013
Messages
91
Hi,

Would anyone know why below is not working ? i get a debug error !

Thanks

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)Dim previousRow As Long
  Dim vOffset As Double
  Dim currentRow As Long
   currentRow = Me.Application.ActiveWindow.ScrollRow
   If previousRow <> currentRow Then
     If previousRow = 0 Then
     previousRow = Me.Application.ActiveWindow.ScrollRow
   End If
    'reposition charts
    For Each c In ActiveSheet.ChartObjects
    vOffset = c.Top – Me.Rows(previousRow).Top
    c.Top = Me.Rows(currentRow).Top + vOffset
    Next c
    previousRow = currentRow
  End If
End Sub
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Ok i was bit busy so couldn't get back. Now please explain your problem in detail and for what you want this code to work. Upon your explanation we will develop our own code that fits our needs.
 
Upvote 0
Ok i was bit busy so couldn't get back. Now please explain your problem in detail and for what you want this code to work. Upon your explanation we will develop our own code that fits our needs.

I am trying to make a chart float when you scroll up and down. This code above is suppose to do that but I don't know why it is not working :(

p.s sorry I was away hence the late reply, thanks.
 
Upvote 0
Try it now and let me know. By the way how is your code getting activated? Is it at time when you try to scroll sheets or when you load the workbook?
Code:
Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim previousRow As Long, c As ChartObject
  Dim vOffset As Double
  Dim currentRow As Long
   currentRow = Me.Application.ActiveWindow.ScrollRow
   If previousRow <> currentRow Then
     If previousRow = 0 Then
     previousRow = Me.Application.ActiveWindow.ScrollRow
   End If
    'reposition charts
    For Each c In ActiveSheet.ChartObjects
        vOffset = c.Top - Me.Rows(previousRow).Top
        c.Top = Me.Rows(currentRow).Top + vOffset
    Next c
    previousRow = currentRow
  End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,415
Messages
6,119,382
Members
448,889
Latest member
TS_711

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