excel - 将主表中的多个表与属性(函数)结合起来
问题描述
我正在尝试使用对象和宏组合多个表。
我发现将多个表行合并到主表
中,这里提出了一个有效的代码片段。
我的问题是我在单元格(函数)中有超链接。当我使用宏组合表格时,不会传输超链接。
如何修改代码以同时传输超链接?
我想到了类似的东西:
Intersect(loDest.ListColumns(lc.Name).Range.EntireColumn, rDest).Hyperlinks = loDest.ListColumns(lc.Name).Range.EntireColumn.Hyperlinks(1).Address
这是来自 jeffreyweir 的代码:
Sub CombineTables(loDest As ListObject, Optional lcSource As ListColumn)
Dim ws As Worksheet
Dim lo As ListObject
Dim lc As ListColumn
Dim rDest As Range
Dim lDestRows As Long
Dim lSourceRows As Long
Application.ScreenUpdating = False
If lcSource Is Nothing Then Set lcSource = loDest.ListColumns(1)
If loDest.ListRows.Count > 0 Then loDest.DataBodyRange.Delete
For Each ws In ActiveWorkbook.Worksheets
For Each lo In ws.ListObjects
If lo <> loDest Then
With lo
If InStr(.Name, loDest.Name & "_") > 0 Then
On Error Resume Next
lDestRows = loDest.ListRows.Count
On Error GoTo 0
lSourceRows = .ListRows.Count
If lSourceRows > 0 Then
'Work out where we want to paste the data to
Set rDest = loDest.HeaderRowRange.Offset(1 + lDestRows).Resize(lSourceRows)
'Resize the destination table
loDest.Resize loDest.Range.Resize(1 + lSourceRows + lDestRows)
For Each lc In .ListColumns
Intersect(loDest.ListColumns(lc.Name).Range.EntireColumn, rDest).Value2 = lc.DataBodyRange.Value
Next lc
Set lc = Nothing
On Error Resume Next
Set lc = .ListColumns(lcSource.Name)
On Error GoTo 0
If lc Is Nothing Then Intersect(lcSource.Range, rDest.EntireRow).Value2 = ws.Name
End If
End If
End With
End If
Next lo
Next ws
Application.ScreenUpdating = True
End Sub
呼叫者:
Sub CombineTables_Caller()
CombineTables [SomeName].ListObject, [SomeName].ListObject.ListColumns("Source")
End Sub
解决方案
推荐阅读
- go - 为什么我不能使用 DefaultClient 访问日历 API?
- python-3.x - Python如何检查字符串是UTC时间戳?
- c# - Razor Pages PageModel 返回 Null 属性
- c# - 系统找不到使用 NUnit3 控制台和 testparam 指定的文件
- r - 测试模块化 R Shiny (golem) 仪表板
- python - 给定一个矩阵 A,以取决于 A 的单射、满射和双射性质的方式返回一个向量 v
- c++ - 将 Visual Studio C++ 游戏发送给不是程序员的朋友
- gem-fury - Gemfury 是否可以防止依赖混淆?
- python - 如何使用 folium 在 Python 中保存地图部分
- python - 将嵌套的 Json 文件展平为 pandas 数据框