hedgedandlevered
hedgedandlevered

Reputation: 2384

move a macro-image with a different macro-image in excel

I have a macro that does this

 ThisWorkbook.Worksheets("data").Range("A50").End(xlToRight).Select

which moves the view to a column way far to the right (so the user doesn't have to scroll, since its common to want to go there) and I want another button that exists on the spreadsheet (as an image) to move above that spot when clicked (which would navigate back).

I tried cut and paste like

ActiveSheet.Shapes.Range(Array("Picture 23")).Select
Selection.Cut
ThisWorkbook.Worksheets("data").Range("A50").End(xlToRight).Offset(-2,0).Select
ActiveSheet.Paste

but that just pastes the image, there is no longer a macro associated with it.

By playing around with record macro I noticed that this happens when I move the picture around

Selection.ShapeRange.IncrementLeft -607.8260629921

but I don't know how to make that variable. what is that 607, pixels? if so, is there a way I can derive the "length" from a known cell to the active cell? The place I'm navigating from, the first button, is static.

Upvotes: 0

Views: 124

Answers (1)

Tim Williams
Tim Williams

Reputation: 166146

Dim rng as Range

With ThisWorkbook.Worksheets("data")

    Set rng = .Range("A50").End(xlToRight)

    rng.Select

    With .Shapes("Picture 23")
       .Top = rng.offset(-1,0).Top
       .Left= rng.Left
    End With

End with

Upvotes: 1

Related Questions