回答編集履歴
1
追記
test
CHANGED
@@ -23,3 +23,127 @@
|
|
23
23
|
1つのファイルが300セル分なら、検索する値が10万個とかにはならないかなと思います。
|
24
24
|
|
25
25
|
全てを1回変数なりシート上なりに全部まとめてから、検索してみては?
|
26
|
+
|
27
|
+
|
28
|
+
|
29
|
+
---
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
以下サンプルコード(※概略のイメージです)
|
34
|
+
|
35
|
+
|
36
|
+
|
37
|
+
```ExcelVBA
|
38
|
+
|
39
|
+
Option Explicit
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
Dim mFSO As FileSystemObject
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
Sub test()
|
48
|
+
|
49
|
+
Dim sPath As String
|
50
|
+
|
51
|
+
Dim sFiles As Variant
|
52
|
+
|
53
|
+
Dim v As Variant
|
54
|
+
|
55
|
+
Dim c As Range
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
Set mFSO = New FileSystemObject
|
60
|
+
|
61
|
+
Application.ScreenUpdating = False
|
62
|
+
|
63
|
+
|
64
|
+
|
65
|
+
'フォルダーのパス指定
|
66
|
+
|
67
|
+
sPath = GetPath()
|
68
|
+
|
69
|
+
'対象ファイルのフルパスのリスト作成
|
70
|
+
|
71
|
+
sFiles = GetFiles(sPath)
|
72
|
+
|
73
|
+
'対象ファイルの値をリスト化
|
74
|
+
|
75
|
+
v = GetList(oFiles)
|
76
|
+
|
77
|
+
'リストをシート上に転記
|
78
|
+
|
79
|
+
Set c = Range("F1").Resize(UBound(v))
|
80
|
+
|
81
|
+
c.Value = WorksheetFunction.Transpose(v)
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
'各値の存在確認
|
86
|
+
|
87
|
+
With Range("A1:A100").Offset(, 1)
|
88
|
+
|
89
|
+
.Formula = "=If(Countif(" & c.Address & ",A1),True,False)"
|
90
|
+
|
91
|
+
.Value = .Value
|
92
|
+
|
93
|
+
Next
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
'リストの消去
|
98
|
+
|
99
|
+
c.ClearContents
|
100
|
+
|
101
|
+
End Sub
|
102
|
+
|
103
|
+
|
104
|
+
|
105
|
+
'複数ファイルの値を一次配列へリスト化
|
106
|
+
|
107
|
+
Private Function GetList(ByRef vv As Variant) As Variant
|
108
|
+
|
109
|
+
Dim v As Variant
|
110
|
+
|
111
|
+
Dim r() As Variant
|
112
|
+
|
113
|
+
Dim i As Long, j As Long, k As Variant
|
114
|
+
|
115
|
+
Dim wb As Workbook
|
116
|
+
|
117
|
+
|
118
|
+
|
119
|
+
ReDim r(1 To 100000)
|
120
|
+
|
121
|
+
For Each v In vv
|
122
|
+
|
123
|
+
Set wb = Workbooks.Open(v)
|
124
|
+
|
125
|
+
k = WorksheetFunction.Transpose(wb.Worksheets(1).Range("U1:U300"))
|
126
|
+
|
127
|
+
wb.Close False
|
128
|
+
|
129
|
+
|
130
|
+
|
131
|
+
For j = 1 To 300
|
132
|
+
|
133
|
+
i = i + 1
|
134
|
+
|
135
|
+
r(i) = k(j)
|
136
|
+
|
137
|
+
Next
|
138
|
+
|
139
|
+
Next
|
140
|
+
|
141
|
+
|
142
|
+
|
143
|
+
ReDim Preserve r(i To i)
|
144
|
+
|
145
|
+
GetList = r
|
146
|
+
|
147
|
+
End Function
|
148
|
+
|
149
|
+
```
|