【发布时间】:2018-12-27 15:56:32
【问题描述】:
我想计算一列中有数据的单元格的数量。
我必须从所有工作簿中计算这些单元格。
例如,我有 2 个工作簿:WB1 和 WB2。
- A1、A2、A3、A4 中包含数据的工作表 WS1
- 工作表 WS2 与 A1、A2 中的数据。
- 我的输出应该显示 6。
这个怎么算?
Option Explicit
Private Sub CommandButton1_Click()
Dim paths(), wbs() As Workbook
Dim x As Integer
Dim sh, rn, k
paths = Application.GetOpenFilename(FileFilter:="Excel Files (*.XLSX), *.XLSX", _
MultiSelect:=True, Title:="Please browse all the Rawdata files")
For x = 1 To UBound(paths)
ReDim wbs(UBound(paths))
Set wbs(x) = Workbooks.Open(paths(x))
Set sh = wbs(x).Sheets("Role ID - Description")
Set rn = sh.UsedRange
k = rn.Rows.Count + rn.Row - 1 - 1
wbs(x).Close
Next
End Sub
【问题讨论】:
-
你有什么样的“麻烦”?