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

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
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,223,099
Messages
6,170,108
Members
452,302
Latest member
TaMere

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