这是我在您的精彩论坛上的第三个主题-我已经获得了非常有用的答案和帮助!
我的下一个问题是将值“超链接”到其原始单元格。我对文件中的数据过滤进行了截屏。
这些术语显示在过滤列表中。单击术语时,可以看到选项卡和单元格是从中提取的。我需要的是将此信息转换为超链接,以便用户可以单击该术语并直接发送到该标签上,在该标签上可以找到更多信息。
我希望这已经足够清楚了……:/您能再帮我一次吗?
答案 0 :(得分:2)
Excel中的书签与超链接类似,不同之处在于,书签用于创建指向当前工作表上特定区域或同一Excel文件中不同工作表的链接。
虽然超链接使用文件名来创建到其他Excel文件的链接,但是书签使用单元格引用和工作表名来创建链接。
下面的示例在同一Excel工作表中的不同位置创建一个书签。
答案 1 :(得分:1)
我认为在Excel中没有任何简单的方法可以做到这一点。一种方法是选择所有值,然后以常规方式进行操作,即一定范围的单元格将获得相同的超链接引用。对于单个单元格,这是乏味的Ctrl + K并手动应用。
但是,这将加快处理速度。通过遍历列和单元格,这将使您所有的单元格引用都基于可单击的超链接,基于它们的单元格值(或更具体地讲,单元格引用/“公式”引用)。
For j = 3 To 4
->表示我们从C列循环到D列,如果需要循环更多列,只需添加数字即可。For i = 6 To lrow
->我们从第6行循环到最后一行(lrow
)。ActiveSheet.
。超链接功能仅接受像A$D2
这样的链接引用,但是当我们选择一个单元格时,我们会有一个像=A!$D2
这样的单元格引用。因此,带有替换行的代码将删除=
,$
个字符。
VBA代码
Sub AddMultipleHyperlinksByCellReference()
Dim ws As Worksheet
For Each ws In ActiveWorkbook.Worksheets
ws.Visible = xlSheetVisible 'First make all worksheets visible/unhidden to prevent broken links.
Next ws
Dim lrow As Long
Dim myString As String
Dim myNewString As String
Dim j As Long
Dim i As Long
If (ActiveSheet.AutoFilterMode And ActiveSheet.FilterMode) Or ActiveSheet.FilterMode Then 'Check if any filter is applied
ActiveSheet.ShowAllData 'Unhide all filterering if filter is on
End If
For j = 3 To 4 'Loop from Column 3 and 4 (Column C and D)
lrow = ActiveSheet.Cells(Rows.Count, j).End(xlUp).Row 'Find last row in current sheet
For i = 6 To lrow 'Loop from row 6 to Last row
myString = ActiveSheet.Range(Cells(i, j), Cells(i, j)).Formula 'Get current cells reference i.e. =A!$D2
myNewString = Replace(myString, "=", "") 'Remove "=" character from string i.e. A!$D2
myNewString = Replace(myNewString, "$", "") 'Remove "$" character from string i.e. A!D2, this is the value SubAddress will accept as link reference
'Below part creates the actually link according to the row "i", column "j" and uses the variable "myNewString" as link reference
ActiveSheet.Hyperlinks.Add Anchor:=Range(Cells(i, j), Cells(i, j)), Address:="", SubAddress:= _
myNewString
Next i
Next j
End Sub
别忘了为您的工作簿制作备份副本,然后应用该宏。 。如果隐藏了工作表,然后单击链接,它将出现因为该链接不起作用...
结果:
正如您所发现的,您可以避免使用超链接(超链接将是精确的!,因此它们会将您定向到特定的单元格),而只需重定向到工作表即可。我做了一些尝试,但是行为却不理想...我认为CASE适用于单个值(单元格A2 = 1)或范围(从10到20)...不适用于单元格范围。
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
Select Case Target.Address
Case "$B$2" To "B$11"
Sheets("A").Visible = True
Sheets("A").Activate
Case "$C$2:$C$10" 'This second statement will never be executed, since CASE only take the first part... I think you need to loop the selected range to make it execute..
Sheets("B").Visible = True
Sheets("B").Activate
End Select
End Sub
隐藏工作表:
由于您要隐藏当前未访问的其他工作表上的列,因此我们需要指定要影响的工作表。
因此将工作表“ A”的C列隐藏到D列。
Worksheets("A").Columns("C:D").EntireColumn.Hidden = True 'Hide Spanish and English for Sheet A
但是,如果工作表已经隐藏了特定的列,那么该代码将给您一个错误。
因此,我们在上面的代码之前添加此行(取消隐藏工作表“ A”中的所有列):
Worksheets("A").Columns.EntireColumn.Hidden = False 'Unhide everything in Sheet A
这需要对所有工作表字母和所有组合(FR&EN,FR&DE,FR&SP)进行。
完整代码:
Sub Hide_Spanish_And_English()
'Hide Spanish And English Columns for all Letter Sheet
Worksheets("A").Columns.EntireColumn.Hidden = False 'Unhide everything in Sheet A
Worksheets("B").Columns.EntireColumn.Hidden = False 'Unhide everything in Sheet B
Worksheets("C").Columns.EntireColumn.Hidden = False 'Unhide everything in Sheet C
Worksheets("D").Columns.EntireColumn.Hidden = False 'Unhide everything in Sheet D
Worksheets("E").Columns.EntireColumn.Hidden = False 'Unhide everything in Sheet E
Worksheets("F").Columns.EntireColumn.Hidden = False 'Unhide everything in Sheet F
Worksheets("G").Columns.EntireColumn.Hidden = False 'Unhide everything in Sheet G
Worksheets("H").Columns.EntireColumn.Hidden = False 'Unhide everything in Sheet H
Worksheets("I").Columns.EntireColumn.Hidden = False 'Unhide everything in Sheet I
Worksheets("J").Columns.EntireColumn.Hidden = False 'Unhide everything in Sheet J
Worksheets("K").Columns.EntireColumn.Hidden = False 'Unhide everything in Sheet K
Worksheets("L").Columns.EntireColumn.Hidden = False 'Unhide everything in Sheet L
Worksheets("M").Columns.EntireColumn.Hidden = False 'Unhide everything in Sheet M
Worksheets("N").Columns.EntireColumn.Hidden = False 'Unhide everything in Sheet N
Worksheets("O").Columns.EntireColumn.Hidden = False 'Unhide everything in Sheet O
Worksheets("P").Columns.EntireColumn.Hidden = False 'Unhide everything in Sheet P
Worksheets("Q").Columns.EntireColumn.Hidden = False 'Unhide everything in Sheet Q
Worksheets("R").Columns.EntireColumn.Hidden = False 'Unhide everything in Sheet R
Worksheets("S").Columns.EntireColumn.Hidden = False 'Unhide everything in Sheet S
Worksheets("T").Columns.EntireColumn.Hidden = False 'Unhide everything in Sheet T
Worksheets("U").Columns.EntireColumn.Hidden = False 'Unhide everything in Sheet U
Worksheets("V").Columns.EntireColumn.Hidden = False 'Unhide everything in Sheet V
Worksheets("W").Columns.EntireColumn.Hidden = False 'Unhide everything in Sheet W
Worksheets("X").Columns.EntireColumn.Hidden = False 'Unhide everything in Sheet X
Worksheets("Y").Columns.EntireColumn.Hidden = False 'Unhide everything in Sheet Y
Worksheets("Z").Columns.EntireColumn.Hidden = False 'Unhide everything in Sheet Z
Worksheets("A").Columns("C:D").EntireColumn.Hidden = True 'Hide Spanish and English for Sheet A
Worksheets("B").Columns("C:D").EntireColumn.Hidden = True 'Hide Spanish and English for Sheet B
Worksheets("C").Columns("C:D").EntireColumn.Hidden = True 'Hide Spanish and English for Sheet C
Worksheets("D").Columns("C:D").EntireColumn.Hidden = True 'Hide Spanish and English for Sheet D
Worksheets("E").Columns("C:D").EntireColumn.Hidden = True 'Hide Spanish and English for Sheet E
Worksheets("F").Columns("C:D").EntireColumn.Hidden = True 'Hide Spanish and English for Sheet F
Worksheets("G").Columns("C:D").EntireColumn.Hidden = True 'Hide Spanish and English for Sheet G
Worksheets("H").Columns("C:D").EntireColumn.Hidden = True 'Hide Spanish and English for Sheet H
Worksheets("I").Columns("C:D").EntireColumn.Hidden = True 'Hide Spanish and English for Sheet I
Worksheets("J").Columns("C:D").EntireColumn.Hidden = True 'Hide Spanish and English for Sheet J
Worksheets("K").Columns("C:D").EntireColumn.Hidden = True 'Hide Spanish and English for Sheet K
Worksheets("L").Columns("C:D").EntireColumn.Hidden = True 'Hide Spanish and English for Sheet L
Worksheets("M").Columns("C:D").EntireColumn.Hidden = True 'Hide Spanish and English for Sheet M
Worksheets("N").Columns("C:D").EntireColumn.Hidden = True 'Hide Spanish and English for Sheet N
Worksheets("O").Columns("C:D").EntireColumn.Hidden = True 'Hide Spanish and English for Sheet O
Worksheets("P").Columns("C:D").EntireColumn.Hidden = True 'Hide Spanish and English for Sheet P
Worksheets("Q").Columns("C:D").EntireColumn.Hidden = True 'Hide Spanish and English for Sheet Q
Worksheets("R").Columns("C:D").EntireColumn.Hidden = True 'Hide Spanish and English for Sheet R
Worksheets("S").Columns("C:D").EntireColumn.Hidden = True 'Hide Spanish and English for Sheet S
Worksheets("T").Columns("C:D").EntireColumn.Hidden = True 'Hide Spanish and English for Sheet T
Worksheets("U").Columns("C:D").EntireColumn.Hidden = True 'Hide Spanish and English for Sheet U
Worksheets("V").Columns("C:D").EntireColumn.Hidden = True 'Hide Spanish and English for Sheet V
Worksheets("W").Columns("C:D").EntireColumn.Hidden = True 'Hide Spanish and English for Sheet W
Worksheets("X").Columns("C:D").EntireColumn.Hidden = True 'Hide Spanish and English for Sheet X
Worksheets("Y").Columns("C:D").EntireColumn.Hidden = True 'Hide Spanish and English for Sheet Y
Worksheets("Z").Columns("C:D").EntireColumn.Hidden = True 'Hide Spanish and English for Sheet Z
End Sub
Sub Hide_English_And_German()
'Hide English And German Columns for all Letter Sheet
Worksheets("A").Columns.EntireColumn.Hidden = False 'Unhide everything in Sheet A
Worksheets("B").Columns.EntireColumn.Hidden = False 'Unhide everything in Sheet B
Worksheets("C").Columns.EntireColumn.Hidden = False 'Unhide everything in Sheet C
Worksheets("D").Columns.EntireColumn.Hidden = False 'Unhide everything in Sheet D
Worksheets("E").Columns.EntireColumn.Hidden = False 'Unhide everything in Sheet E
Worksheets("F").Columns.EntireColumn.Hidden = False 'Unhide everything in Sheet F
Worksheets("G").Columns.EntireColumn.Hidden = False 'Unhide everything in Sheet G
Worksheets("H").Columns.EntireColumn.Hidden = False 'Unhide everything in Sheet H
Worksheets("I").Columns.EntireColumn.Hidden = False 'Unhide everything in Sheet I
Worksheets("J").Columns.EntireColumn.Hidden = False 'Unhide everything in Sheet J
Worksheets("K").Columns.EntireColumn.Hidden = False 'Unhide everything in Sheet K
Worksheets("L").Columns.EntireColumn.Hidden = False 'Unhide everything in Sheet L
Worksheets("M").Columns.EntireColumn.Hidden = False 'Unhide everything in Sheet M
Worksheets("N").Columns.EntireColumn.Hidden = False 'Unhide everything in Sheet N
Worksheets("O").Columns.EntireColumn.Hidden = False 'Unhide everything in Sheet O
Worksheets("P").Columns.EntireColumn.Hidden = False 'Unhide everything in Sheet P
Worksheets("Q").Columns.EntireColumn.Hidden = False 'Unhide everything in Sheet Q
Worksheets("R").Columns.EntireColumn.Hidden = False 'Unhide everything in Sheet R
Worksheets("S").Columns.EntireColumn.Hidden = False 'Unhide everything in Sheet S
Worksheets("T").Columns.EntireColumn.Hidden = False 'Unhide everything in Sheet T
Worksheets("U").Columns.EntireColumn.Hidden = False 'Unhide everything in Sheet U
Worksheets("V").Columns.EntireColumn.Hidden = False 'Unhide everything in Sheet V
Worksheets("W").Columns.EntireColumn.Hidden = False 'Unhide everything in Sheet W
Worksheets("X").Columns.EntireColumn.Hidden = False 'Unhide everything in Sheet X
Worksheets("Y").Columns.EntireColumn.Hidden = False 'Unhide everything in Sheet Y
Worksheets("Z").Columns.EntireColumn.Hidden = False 'Unhide everything in Sheet Z
Worksheets("A").Range("C1,E1").EntireColumn.Hidden = True 'Hide English and German for Sheet A
Worksheets("B").Range("C1,E1").EntireColumn.Hidden = True 'Hide English and German for Sheet B
Worksheets("C").Range("C1,E1").EntireColumn.Hidden = True 'Hide English and German for Sheet C
Worksheets("D").Range("C1,E1").EntireColumn.Hidden = True 'Hide English and German for Sheet D
Worksheets("E").Range("C1,E1").EntireColumn.Hidden = True 'Hide English and German for Sheet E
Worksheets("F").Range("C1,E1").EntireColumn.Hidden = True 'Hide English and German for Sheet F
Worksheets("G").Range("C1,E1").EntireColumn.Hidden = True 'Hide English and German for Sheet G
Worksheets("H").Range("C1,E1").EntireColumn.Hidden = True 'Hide English and German for Sheet H
Worksheets("I").Range("C1,E1").EntireColumn.Hidden = True 'Hide English and German for Sheet I
Worksheets("J").Range("C1,E1").EntireColumn.Hidden = True 'Hide English and German for Sheet J
Worksheets("K").Range("C1,E1").EntireColumn.Hidden = True 'Hide English and German for Sheet K
Worksheets("L").Range("C1,E1").EntireColumn.Hidden = True 'Hide English and German for Sheet L
Worksheets("M").Range("C1,E1").EntireColumn.Hidden = True 'Hide English and German for Sheet M
Worksheets("N").Range("C1,E1").EntireColumn.Hidden = True 'Hide English and German for Sheet N
Worksheets("O").Range("C1,E1").EntireColumn.Hidden = True 'Hide English and German for Sheet O
Worksheets("P").Range("C1,E1").EntireColumn.Hidden = True 'Hide English and German for Sheet P
Worksheets("Q").Range("C1,E1").EntireColumn.Hidden = True 'Hide English and German for Sheet Q
Worksheets("R").Range("C1,E1").EntireColumn.Hidden = True 'Hide English and German for Sheet R
Worksheets("S").Range("C1,E1").EntireColumn.Hidden = True 'Hide English and German for Sheet S
Worksheets("T").Range("C1,E1").EntireColumn.Hidden = True 'Hide English and German for Sheet T
Worksheets("U").Range("C1,E1").EntireColumn.Hidden = True 'Hide English and German for Sheet U
Worksheets("V").Range("C1,E1").EntireColumn.Hidden = True 'Hide English and German for Sheet V
Worksheets("W").Range("C1,E1").EntireColumn.Hidden = True 'Hide English and German for Sheet W
Worksheets("X").Range("C1,E1").EntireColumn.Hidden = True 'Hide English and German for Sheet X
Worksheets("Y").Range("C1,E1").EntireColumn.Hidden = True 'Hide English and German for Sheet Y
Worksheets("Z").Range("C1,E1").EntireColumn.Hidden = True 'Hide English and German for Sheet Z
End Sub
Sub Hide_Spanish_And_German()
'Hide Spanish And German Columns for all Letter Sheet
Worksheets("A").Columns.EntireColumn.Hidden = False 'Unhide everything in Sheet A
Worksheets("B").Columns.EntireColumn.Hidden = False 'Unhide everything in Sheet B
Worksheets("C").Columns.EntireColumn.Hidden = False 'Unhide everything in Sheet C
Worksheets("D").Columns.EntireColumn.Hidden = False 'Unhide everything in Sheet D
Worksheets("E").Columns.EntireColumn.Hidden = False 'Unhide everything in Sheet E
Worksheets("F").Columns.EntireColumn.Hidden = False 'Unhide everything in Sheet F
Worksheets("G").Columns.EntireColumn.Hidden = False 'Unhide everything in Sheet G
Worksheets("H").Columns.EntireColumn.Hidden = False 'Unhide everything in Sheet H
Worksheets("I").Columns.EntireColumn.Hidden = False 'Unhide everything in Sheet I
Worksheets("J").Columns.EntireColumn.Hidden = False 'Unhide everything in Sheet J
Worksheets("K").Columns.EntireColumn.Hidden = False 'Unhide everything in Sheet K
Worksheets("L").Columns.EntireColumn.Hidden = False 'Unhide everything in Sheet L
Worksheets("M").Columns.EntireColumn.Hidden = False 'Unhide everything in Sheet M
Worksheets("N").Columns.EntireColumn.Hidden = False 'Unhide everything in Sheet N
Worksheets("O").Columns.EntireColumn.Hidden = False 'Unhide everything in Sheet O
Worksheets("P").Columns.EntireColumn.Hidden = False 'Unhide everything in Sheet P
Worksheets("Q").Columns.EntireColumn.Hidden = False 'Unhide everything in Sheet Q
Worksheets("R").Columns.EntireColumn.Hidden = False 'Unhide everything in Sheet R
Worksheets("S").Columns.EntireColumn.Hidden = False 'Unhide everything in Sheet S
Worksheets("T").Columns.EntireColumn.Hidden = False 'Unhide everything in Sheet T
Worksheets("U").Columns.EntireColumn.Hidden = False 'Unhide everything in Sheet U
Worksheets("V").Columns.EntireColumn.Hidden = False 'Unhide everything in Sheet V
Worksheets("W").Columns.EntireColumn.Hidden = False 'Unhide everything in Sheet W
Worksheets("X").Columns.EntireColumn.Hidden = False 'Unhide everything in Sheet X
Worksheets("Y").Columns.EntireColumn.Hidden = False 'Unhide everything in Sheet Y
Worksheets("Z").Columns.EntireColumn.Hidden = False 'Unhide everything in Sheet Z
Worksheets("A").Columns("D:E").EntireColumn.Hidden = True 'Hide Spanish and German for Sheet A
Worksheets("B").Columns("D:E").EntireColumn.Hidden = True 'Hide Spanish and German for Sheet B
Worksheets("C").Columns("D:E").EntireColumn.Hidden = True 'Hide Spanish and German for Sheet C
Worksheets("D").Columns("D:E").EntireColumn.Hidden = True 'Hide Spanish and German for Sheet D
Worksheets("E").Columns("D:E").EntireColumn.Hidden = True 'Hide Spanish and German for Sheet E
Worksheets("F").Columns("D:E").EntireColumn.Hidden = True 'Hide Spanish and German for Sheet F
Worksheets("G").Columns("D:E").EntireColumn.Hidden = True 'Hide Spanish and German for Sheet G
Worksheets("H").Columns("D:E").EntireColumn.Hidden = True 'Hide Spanish and German for Sheet H
Worksheets("I").Columns("D:E").EntireColumn.Hidden = True 'Hide Spanish and German for Sheet I
Worksheets("J").Columns("D:E").EntireColumn.Hidden = True 'Hide Spanish and German for Sheet J
Worksheets("K").Columns("D:E").EntireColumn.Hidden = True 'Hide Spanish and German for Sheet K
Worksheets("L").Columns("D:E").EntireColumn.Hidden = True 'Hide Spanish and German for Sheet L
Worksheets("M").Columns("D:E").EntireColumn.Hidden = True 'Hide Spanish and German for Sheet M
Worksheets("N").Columns("D:E").EntireColumn.Hidden = True 'Hide Spanish and German for Sheet N
Worksheets("O").Columns("D:E").EntireColumn.Hidden = True 'Hide Spanish and German for Sheet O
Worksheets("P").Columns("D:E").EntireColumn.Hidden = True 'Hide Spanish and German for Sheet P
Worksheets("Q").Columns("D:E").EntireColumn.Hidden = True 'Hide Spanish and German for Sheet Q
Worksheets("R").Columns("D:E").EntireColumn.Hidden = True 'Hide Spanish and German for Sheet R
Worksheets("S").Columns("D:E").EntireColumn.Hidden = True 'Hide Spanish and German for Sheet S
Worksheets("T").Columns("D:E").EntireColumn.Hidden = True 'Hide Spanish and German for Sheet T
Worksheets("U").Columns("D:E").EntireColumn.Hidden = True 'Hide Spanish and German for Sheet U
Worksheets("V").Columns("D:E").EntireColumn.Hidden = True 'Hide Spanish and German for Sheet V
Worksheets("W").Columns("D:E").EntireColumn.Hidden = True 'Hide Spanish and German for Sheet W
Worksheets("X").Columns("D:E").EntireColumn.Hidden = True 'Hide Spanish and German for Sheet X
Worksheets("Y").Columns("D:E").EntireColumn.Hidden = True 'Hide Spanish and German for Sheet Y
Worksheets("Z").Columns("D:E").EntireColumn.Hidden = True 'Hide Spanish and German for Sheet Z
End Sub