|
发表于 2022-1-27 17:52
|
显示全部楼层
本楼为最佳答案
你再试试
Private Sub Worksheet_Activate()
If Range("A201") = "" Then
Range("A1:AZ1").ClearContents '清除数据
JG = InputBox("请输入各单位间隔空列数:", "间距设置", 5)
If JG <> "" Then
Range("A201") = JG
ARR = Array("甲单位", "乙单位", "丙单位", "丁单位", "所有单位") '列标内容
For I = 0 To UBound(ARR)
Cells(1, I * (JG + 1) + 1) = ARR(I) '输入列标
Next
Else
JG = 5
End If
Else: Exit Sub
End If
Range("A4:AZ200").ClearContents '清除数据
For Sh = 3 To Sheets.Count
NM = Sheets(Sh).Name
N = (Asc(UCase(Left(NM, 1))) - 64)
If N > 0 And N < 27 Then
N = (N - 1) * (JG + 1) + 1 '求列号(序号)
W = Cells(200, N).End(3).Row + 1 '求最后一行+1
If W < 4 Then W = 4 '避免数据落入前3行
With Cells(W, N)
.Select
.Hyperlinks.Add Anchor:=Selection, Address:="", SubAddress:=NM & "!A1", TextToDisplay:=NM '添加超链接
.Font.Name = "宋体"
.Font.Size = 14
End With
N2 = UBound(ARR) * (JG + 1) + 1
W2 = Cells(500, N2).End(3).Row + 1 '求最后一行+1
If W2 < 4 Then W2 = 4 '避免数据落入前3行
With Cells(W2, N2)
.Select
.Hyperlinks.Add Anchor:=Selection, Address:="", SubAddress:=NM & "!A1", TextToDisplay:=NM '添加超链接
.Font.Name = "宋体"
.Font.Size = 14
End With
Else
N2 = UBound(ARR) * (JG + 1) + 1
W = Cells(500, N2).End(3).Row + 1
If W < 4 Then W = 4
With Cells(W, N2)
.Select
.Hyperlinks.Add Anchor:=Selection, Address:="", SubAddress:=NM & "!A1", TextToDisplay:=NM
.Font.Name = "宋体"
.Font.Size = 14
End With
End If
Next
End Sub
|
|