Help with Macro that Moves Shape

gator2

New Member
Joined
Nov 25, 2008
Messages
36
I have a spreadsheet with 20 charts, each comparing one of our products vs similar products from our competitors, as well as a map for each competitor.

The charts run along the right side of the spreadsheet with the map on the left side. A drop down menu allows you to toggle between maps. The way the rest of the spreadsheet is laid out, there isn't room freeze the maps at the top, so I've written a macro (below) to allow the map to follow you as scroll down to the different maps. Problem is, where ever you click on the spreadsheet is where the map appears. Is there a way to keep it in line with column A?

Thanks in advance for your help.


Private Sub Worksheet_SelectionChange(ByVal Target As Range)


Dim myShape As Shape


Set myShape = Me.Shapes("Competitor A")


With Me.Cells(ActiveWindow.ScrollRow, ActiveWindow.ScrollColumn)
myShape.Top = .Top
myShape.Left = .Left
End With


End Sub
 
Last edited:

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Not sure if this is what you want. It keeps the left of the shape pinned to the left of column A - so the shape is only visible if column A is visible on the screen

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)

Dim myShape As Shape
Set myShape = Me.Shapes("Competitor A")

With Me.Cells(ActiveWindow.ScrollRow, ActiveWindow.ScrollColumn)
    myShape.Top = .Top
    myShape.Left = [COLOR=#ff0000]Range("A1").Left[/COLOR]
End With

End Sub
 
Upvote 0
I'd like to change up my spreadsheet, with the goal of "fencing in" the map between columns A-G, and being able to scroll through columns H on to view the chart and graph, as they're too large to see on the screen. When I freeze panes and click on a cell, rather than staying in line with column A, the image jumps over the freeze pane line at column H.

Here's is the current vba code. Is it possible to prevent this? Thanks for the help.

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

Dim myShape As Shape
Set myShape = Me.Shapes("Competitor A")

With Me.Cells(ActiveWindow.ScrollRow, ActiveWindow.ScrollColumn)
myShape.Top = .Top
myShape.Left = Range("A1").Left
End With

End Sub
 
Upvote 0

Forum statistics

Threads
1,214,946
Messages
6,122,401
Members
449,081
Latest member
JAMES KECULAH

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