简体   繁体   English

在 excel VBA 中,如何让我的屏幕跟随图像,无论它走到哪里?

[英]In excel VBA, how do I make my screen follow the image, wherever it goes?

I wanted to ask someone how to make the screen follow a image in VBA excel.我想问某人如何使屏幕跟随 VBA excel 中的图像。 (Image's top left cell: M12, Screen's top left cell: A1) (图片左上角单元格:M12,屏幕左上角单元格:A1)

I have this table in Excel:我在 Excel 中有这个表:

1    |A
2    |B
3    |C
4    |D
5    |E
6    |F
7    |G
8    |H
10   |I
11   |J
12   |K
13   |L
14   |M
15   |N
16   |O
...  |...

(That is not a code.) (那不是代码。)

To convert letters in the ranges to numbers so I can subtract them.将范围内的字母转换为数字,以便我可以减去它们。

This is my VBA code:这是我的 VBA 代码:

Sub PicScroll()
'Variables
Dim Ws As Worksheet
Dim Picpos As Range
Dim a As Shape

'Set variables
Set Ws = ThisWorkbook.Worksheets("Game")
Set a = ActiveSheet.Shapes("Picture 2")
Set Picpos = a.TopLeftCell

'Loop
Do Until 1 = 0

'Code
Appication.Goto Reference:=Worksheets("Game").Range((ActiveSheet.Shapes("Picture 2").TopLeftCell.Row - 11) & _
 (Vlookup(ActiveSheet.Shapes("Picture 2").TopLeftCell.Column - L11.Column),Worksheets("CodeSheet").Range(I1:J77),2,False)), Scroll:=True

'End Loop
Loop
End Sub

CodeSheet is the worksheet that has the table shown on top. CodeSheet 是将表格显示在顶部的工作表。 Game is the worksheet where the image(Picture 2) is.游戏是图像(图2)所在的工作表。

I have some problem with the code in the Application.Goto line.我对Application.Goto行中的代码有一些问题。

Thank you!谢谢!

Try this code:试试这个代码:

Application.Goto Reference:=Worksheets("Game").Cells(a.TopLeftCell.Row - 11, _
        Number2Letter(a.TopLeftCell.Column - Range("L11").Column)), Scroll:=True

But before running, add this Function first at the bottom part of your module:但是在运行之前,先在模块的底部添加这个函数:

Function Number2Letter(ColumnNumber As Long) As String
    Number2Letter = Split(Cells(1, ColumnNumber).Address, "$")(1)
End Function

The function converts column number into column letter.该函数将列号转换为列字母。 This eliminates the need for vlookup.这消除了对 vlookup 的需要。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM