|
一个合并表格的VBA,很好用,想改造成加载项使用,但出现以下问题,就是合并汇总后的单元格真的长数字显示为6.271E+18之类,不知道应该怎么修改,烦请各位大神帮忙!谢谢!不胜感激!!见黄色部分。
问题示例.rar
(132.72 KB, 下载次数: 6)
- Sub 汇总工作簿为总表()
- Dim shtData As Worksheet
- Dim nTitleRow As Long, i As Long, j As Long, nStartRow As Long
- Dim aData, aResult(), rng As Range
- Dim strPath As String, strFileName As String
- Dim nShtCount As Long, k As Long
- ' 选择文件夹
- strPath = IIf(Application.FileDialog(msoFileDialogFolderPicker).Show, _
- Application.FileDialog(msoFileDialogFolderPicker).SelectedItems(1), "")
- If Right(strPath, 1) <> "" Then strPath = strPath & ""
- ' 输入标题行数
- nTitleRow = Val(InputBox("请输入标题的行数,默认标题行数为1", "提醒", 1))
- Application.ScreenUpdating = False: Application.DisplayAlerts = False
- ReDim aResult(1 To 10000, 1 To 100) '这里限制行数和列数
- ' 遍历文件夹内的文件
- strFileName = Dir(strPath & "*.xls*")
- Do While strFileName <> ""
- If strFileName <> ThisWorkbook.Name Then
- With GetObject(strPath & strFileName)
- For Each shtData In .Worksheets
- ' 设置工作表范围
- Set rng = shtData.UsedRange
- ' 检查工作表是否有数据
- If rng.Rows.Count > 1 Then
- nShtCount = nShtCount + 1
- nStartRow = IIf(nShtCount = 1, 1, nTitleRow + 1)
- ' 将工作表数据存储到数组中
- aData = rng.Value
- For i = nStartRow To UBound(aData)
- k = k + 1
- ' 将工作表数据复制到结果数组中
- For j = 1 To UBound(aData, 2)
- aResult(k, j) = aData(i, j) '行数和列数超出范围,运行到这里会出现错误,调增行数和列数即可。
- Next j
- Next i
- End If
- Next shtData
- .Close False
- End With
- End If
- strFileName = Dir
- Loop
- Range("A1").Resize(k, UBound(aResult, 2)) = aResult
- Application.ScreenUpdating = True: Application.DisplayAlerts = True
- End Sub
复制代码
|
|