Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Excel 如何正确链接_Excel_Vba_Hyperlink - Fatal编程技术网

Excel 如何正确链接

Excel 如何正确链接,excel,vba,hyperlink,Excel,Vba,Hyperlink,Sub-GoToPCell() Dim i等于长,j等于整数 作为字符串的Dim PCell 最后一排一样长 变暗rng As范围 附页1.范围(“A:A”) 如果Application.WorksheetFunction.CountA(.Cells)为0,则 设置rng=.SpecialCells(xlCellTypeConstants,1) 设置rng=rng.Areas(rng.Areas.Count) lastrow=rng.Cells(rng.Cells.Count).Row 如果结束

Sub-GoToPCell()
Dim i等于长,j等于整数
作为字符串的Dim PCell
最后一排一样长
变暗rng As范围
附页1.范围(“A:A”)
如果Application.WorksheetFunction.CountA(.Cells)为0,则
设置rng=.SpecialCells(xlCellTypeConstants,1)
设置rng=rng.Areas(rng.Areas.Count)
lastrow=rng.Cells(rng.Cells.Count).Row
如果结束
以
对于i=2到最后一行
如果不是空的(单元格(i,“CT”).End(xlToRight)),则
PCell=单元(i,“CT”)。结束(xlToRight)。地址
ActiveSheet.Hyperlinks.Add单元格(i,2),地址:=“”,子地址:=“'”和Sheet1.Name&“!”和PCell
如果结束
接下来我
端接头

想在左边留下空白单元格而不创建一个名为“当前工作表”的蓝色超链接。

使用<代码> IsEmpty < /Cl>检查这个。@ BigBN可以指定如何包含空吗?我假设使用If语句?
如果不是IsEmpty(Cells(I,Columns.Count).End(xlToLeft)),那么
@BigBen-Hi-BigBen,不确定您是否会看到这个。我应用了IsEmpty,但它保持不变:PCell=Cells(I,“CT”).End(xlToRight)。地址如果不是IsEmpty(PCell),那么。。。代码仍然将空白单元格更改为工作表的名称。你还有其他建议吗?谢谢。不要用字符串呼叫
IsEmpty
Sub GoToPCell()

Dim i As Long, j As Integer
Dim PCell As String
Dim lastrow As Long
Dim rng As Range

With Sheet1.Range("A:A")
If Application.WorksheetFunction.CountA(.Cells) <> 0 Then
Set rng = .SpecialCells(xlCellTypeConstants, 1)
Set rng = rng.Areas(rng.Areas.Count)
lastrow = rng.Cells(rng.Cells.Count).Row
End If
End With

For i = 2 To lastrow

If Not IsEmpty(Cells(i, "CT").End(xlToRight)) Then
PCell = Cells(i, "CT").End(xlToRight).Address
ActiveSheet.Hyperlinks.Add Cells(i, 2), Address:="", SubAddress:="'" & Sheet1.Name & "'!" & PCell
End If

Next i

End Sub