Floating picture - stationary with scroll, moves out of way

Rod684

New Member
Joined
Jan 10, 2006
Messages
2
Hi All,

I'm a newbie here so please be gentle.

I am attempting to insert a picture (text box is acceptable) that remains within the active worksheet view whilst scrolling, but can also move away from active cells when tabbing through the sheet. The picture is a legend and I would like to have it always within view no matter where you are on the spreadsheet.

Thanks in advance.
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
Hopefully this will get you started. Goes into the code module via rightclick sheet tab/view code
Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
    Dim MyPicture As Object
    Dim MyTop As Double
    Dim MyLeft As Double
    Dim BottomRightCell As Range
    '-----------------------------------------------------------
    '- bottom right cell
    With ActiveWindow.VisibleRange
        r = .Rows.Count
        c = .Columns.Count
        Set BottomRightCell = .Cells(r, c)
    End With
    '------------------------------------------------------------
    '- position picture
    Set MyPicture = ActiveSheet.Pictures(1)
    MyTop = BottomRightCell.Top - MyPicture.Height - 5
    MyLeft = BottomRightCell.Left - MyPicture.Width - 5
    With MyPicture
        .Top = MyTop
        .Left = MyLeft
    End With
End Sub
 
Upvote 0
Absolutely magnificent. Does pretty much what I have been trying to do. A little tweaking and it'll be right. I deal with Access most of the time. Until finding this forum I had no idea how pliable Excel was.

Greatly appreciated BrianB.
 
Upvote 0
Great Code.
I am trying to modify it to keep a chart in a specific location as the sheet scrolls but keep getting the error "Object doesn't support property or method". I have tried using it as a procedure and call the procedure from the sheet event and it almost works. I only get a thin black line that moves to the prescribed location upon a new selection. It only works when I use the Shapes object but not the ChartObject or Charts. Could the thin black line be the chart, but the size is screwy? If so, why does the original chart still remain? Any help, This seem like it will be a cool feature if i can get it to work.

Thanks
 
Upvote 0
Alright, how do you make the picture scroll on its own, with this code you have to keep clicking it to keep it in view, i don't or can't use frozen panes and i need it to remain in the top right corner. i prefer a simple auto shape (rounded rectangle) as you can change the appearance more than command buttons and such. did that make sense? just like the web, as you scroll down or up, the picture stays always in view
 
Upvote 0
Anyway to make this code float the picture on the top right corner? (inside a freezed row panes?) Otherwise this code does exactly what I need but it places the image to the bottom right, I need it on the top right.

Thanks
April :)
 
Upvote 0
Hopefully this will get you started. Goes into the code module via rightclick sheet tab/view code
Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
    Dim MyPicture As Object
    Dim MyTop As Double
    Dim MyLeft As Double
    Dim BottomRightCell As Range
    '-----------------------------------------------------------
    '- bottom right cell
    With ActiveWindow.VisibleRange
        r = .Rows.Count
        c = .Columns.Count
        Set BottomRightCell = .Cells(r, c)
    End With
    '------------------------------------------------------------
    '- position picture
    Set MyPicture = ActiveSheet.Pictures(1)
    MyTop = BottomRightCell.Top - MyPicture.Height - 5
    MyLeft = BottomRightCell.Left - MyPicture.Width - 5
    With MyPicture
        .Top = MyTop
        .Left = MyLeft
    End With
End Sub



Anyway to make this code float the picture on the top right corner? (inside a freezed row panes?) Otherwise this code does exactly what I need but it places the image to the bottom right, I need it on the top right.

Thanks
April :)
 
Upvote 0
Anyway to make this code float the picture on the top right corner? (inside a freezed row panes?) Otherwise this code does exactly what I need but it places the image to the bottom right, I need it on the top right.

Thanks
April :)

Thanks BrianB for this bit of code, it's exactly what I was looking for.
Since a few people have asked about making the floating picture locate to the top right here is the slightly modified code for that.

Code:
[SIZE=2][FONT=courier new]Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
    Dim MyPicture As Object
    Dim MyTop As Double
    Dim MyLeft As Double
    Dim TopRightCell As Range
    '-----------------------------------------------------------
    '- top right cell
    With ActiveWindow.VisibleRange[COLOR=#ff0000]
        r = 1
[/COLOR]        c = .Columns.Count
        Set TopRightCell = .Cells(r, c)
    End With
    '------------------------------------------------------------
    '- position picture
    Set MyPicture = ActiveSheet.Pictures(1)
    MyTop = [COLOR=#ff0000]TopRightCell.Top + 5[/COLOR]
    MyLeft = TopRightCell.Left - MyPicture.Width - 5
    With MyPicture
        .Top = MyTop
        .Left = MyLeft
    End With
End Sub
[/FONT][/SIZE]
 
Upvote 0
Plugging in the code above was great! However, the key issue I experienced was that once I used a floating picture, I was unable to Undo and Redo any actions in excel. Is there a viable workaround for this?
 
Upvote 0
Thanks BrianB for this bit of code, it's exactly what I was looking for.
Since a few people have asked about making the floating picture locate to the top right here is the slightly modified code for that.

Hi, could you write a similar code to freeze a small graph to the top-right?
 
Upvote 0

Forum statistics

Threads
1,214,541
Messages
6,120,110
Members
448,945
Latest member
Vmanchoppy

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