|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
一定是有其中的列没有数据
Sub getName()
Dim oBook As Workbook
Dim sht As Worksheet
Dim i, k, j As Integer
Dim colNum
colNum = Array(2, 4, 6) '取列的序号 b,c,d,e,f (2,3,4,5,6)
Dim dic As Object
Dim arr, brr
Set dic = CreateObject("scripting.dictionary")
Sheet1.Range("a:a").ClearContents
Dim path$, file$, str$
path = ThisWorkbook.path & "\"
file = Dir(path & "*.xls*")
Do While file <> ""
If path & file <> ThisWorkbook.FullName Then
Set oBook = Application.Workbooks.Open(path & file)
Set sht = oBook.Worksheets(1)
For i = 1 To 3 '几列,如上面,1 to 5
k = sht.Cells(Rows.Count, colNum(i - 1)).End(xlUp).Row
If k > 1 Then
arr = sht.Range(sht.Cells(1, colNum(i - 1)), sht.Cells(k, colNum(i - 1))).Value
For j = 1 To k
str = arr(j, 1)
If str <> "" And Len(str) > 1 Then
If Asc(Mid(str, 1, 1)) < 0 Then
dic(str) = ""
End If
End If
Next
End If
Next
oBook.Close
End If
file = Dir
Loop
brr = dic.keys
Sheet1.Range("a1").Resize(dic.Count, 1).Value = Application.Transpose(brr)
End Sub |
|