简体   繁体   English

更改出现在 Excel 中多个工作表上的公式

[英]Change the a formula that appears on multiple worksheets in Excel

I have an Excel file that has about ~100 sheets that all contain the same 'main' button.我有一个 Excel 文件,里面有大约 100 张都包含相同的“主”按钮。 This button (which is actually a hyperlink) links to the main worksheet of the Excel file.此按钮(实际上是一个超链接)链接到 Excel 文件的主工作表。 When clicking the button, the main worksheet is opened and cell A1 is selected.单击该按钮时,将打开主工作表并选择单元格 A1。 The problem is that cell A1 and A2 contain an image, and when A1 is selected, this selection is partially "on top" of the image. The problem is that cell A1 and A2 contain an image, and when A1 is selected, this selection is partially "on top" of the image. Functionality wise this is not a problem but it does not look so nice optically.功能明智这不是问题,但它在视觉上看起来不太好。 This leads me to the follow questions:这使我想到以下问题:

  • Is there a way to make the hyperlink select, for example, A1 to F61?有没有办法让超链接选择,例如,A1到F61?
  • If so, is there a way to apply this to the 'main' on every worksheet button automatically?如果是这样,有没有办法将其自动应用于每个工作表按钮上的“主要”?

So, you already know how to change one link.所以,您已经知道如何更改一个链接。 To change all, you may use a macro which:要更改所有内容,您可以使用一个宏:

  1. iterates over all worksheets迭代所有工作表
  2. iterates over all shapes in worksheet迭代工作表中的所有形状
  3. check if link is the one you want to change and检查链接是否是您要更改的链接,然后
  4. change it更改

like following:像下面这样:

Sub ChangeHyperlinks()
    Dim w As Worksheet, s As Shape, h As Hyperlink
    For Each w In ActiveWorkbook.Worksheets
        For Each s In w.Shapes
            Set h = Nothing
            On Error Resume Next
            Set h = s.Hyperlink
            On Error GoTo 0
            If Not h Is Nothing Then
                If h.Address = "" And h.SubAddress = "Your_Main_Worksheet_Name!A5:B6" Then
                    h.SubAddress = "Your_Main_Worksheet_Name!A1:F61"
                End If
            End If
        Next
    Next
End Sub
  • Richt click on you shape (button) Richt 点击你的形状(按钮)
  • Choose hyperlink选择超链接
  • On the left, choose "place in this document"在左侧,选择“放置在此文档中”
  • Type the Reference: Main!F61输入参考:Main!F61

The solution you are trying to achieve is pretty easy.您试图实现的解决方案非常简单。 Just follow the below steps只需按照以下步骤操作

  1. Open the worksheet where you want to link to ('The Main Worksheet').打开要链接到的工作表(“主工作表”)。
  2. Select the range of cells you want to hyperlink to.选择要超链接到的单元格范围。
  3. In the Name Box (Top left where cell address is displayed), try writing a word or any name and then press Enter.在名称框(显示单元格地址的左上角)中,尝试输入单词或任何名称,然后按 Enter。
  4. Select the button (Design Mode), go to Insert Tab, Click on the hyperlink or link (depends on office version) button.选择按钮(设计模式),转到插入选项卡,单击超链接或链接(取决于办公版本)按钮。
  5. In the dialog box, in the 'Link to' select 'Place in This Document', then in Defined Names group, you will see that word or name you gave to the range.在对话框中,在“链接到”中选择“放置在此文档中”,然后在“定义的名称”组中,您将看到您为该范围指定的单词或名称。
  6. Select that, and click on the OK button.选择它,然后单击“确定”按钮。

Done...完毕...

Hope this helps !希望这可以帮助 !

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

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