Здравствуйте! подскажите пожалуйста как мне обращаться не к определенному файлу(как в моем случае "Проверка" ),а к любому файлу из общей папки либо же множественный выбор?
Код
Private Sub CommandButton3_Click()
Dim Period As String
Dim FoundPeriod As Range
Dim iSebest As String
Dim FoundSebest As Range
Dim i As Integer
Dim j As Integer
Dim n As Integer
Dim Sht As Worksheet
Dim Wb_покупки As Workbook
Set Wb_покупки = Workbooks("Проверка")
With Wb_покупки
For j = 1 To 8
Period = Split(.Cells(1, j), "-")(0)
iSebest = Split(.Cells(1, j), "-")(1)
n = 0
For Each Sht In .Worksheets
With Sht
Set FoundPeriod = .Rows(1).Find(Period, , xlValues, xlWhole)
Set FoundSebest = .Columns(1).Find(iSebest, , xlValues, xlWhole)
Cells(2 + n, j) = .Cells(FoundSebest.Row, FoundPeriod.Column)
End With
n = n + 1
Next
Next j
End With
End Sub
Спасибо всем! Попробовала вот так... Subcript out of range не оставляет меня в покое
Код
Private Sub CommandButton3_Click()
Set fd = Application.FileDialog(msoFileDialogOpen)
If fd.Show = -1 Then fd.Execute
Set fd = Nothing
Dim Fact As String
Dim FoundFact As Range
Dim iSebest As String
Dim FoundSebest As Range
Dim i As Integer
Dim j As Integer
Dim n As Integer
Dim Sht As Worksheet
Dim Wb_1 As Workbook
For j = 1 To 4
Fact = Split(Cells(1, j), "-")(0)
iSebest = Split(Cells(1, j), "-")(1)
With Wb_1
n = 0
For Each Sht In .Worksheets
With Sht
Set FoundFact = .Rows(1).Find(Fact, , xlValues, xlWhole)
Set FoundSebest = .Columns(1).Find(iSebest, , xlValues, xlWhole)
Cells(2 + n, j) = .Cells(FoundSebest.Row, FoundFact.Column)
End With
n = n + 1
Next
End With
Next
End Sub