I have a program that is supposed to copy some values from other workbooks and intially I set it up to take values from the specific sell.
For now I am trying to implement search function, not to inster the number of a column manually.
I am trying to use the following functions
Col = wb.Worksheets("Calculation").Rows(2).Find("31.12.2018").Column
But even though, there is a specific value of 31.12.2018 in the file, it is still not working properly.
Also, it was somehow working, until I changed something and can't find the mistake for now. There is a problem as well, if the script doesn't find the data it goes to an error of undefinable object (seems like you can't assign .column, when there is no info found).
strFilter = "Excel Files (*.xls;*.xlsb;*.xlsx),*.xls;*xlsb;*.xlsx"
strTitle = "Select input file (XXXX)"
arrfiles = Application.GetOpenFilename(strFilter, 2, strTitle, , True)
If VarType(arrfiles) = vbBoolean Then Exit Sub
Dim out As String
out = Cells(2, 7)
brow = Cells(2, 8)
bcol = Cells(2, 9)
Dim Target As Range
Dim Source As Range
Dim Col As Integer
For b = 1 To UBound(arrfiles)
Set wb = Workbooks.Open(Filename:=arrfiles(b), UpdateLinks:=False)
lLastRow = wb.Worksheets("Calculation").Cells(Rows.Count, 3).End(xlUp).Row
ThisWorkbook.Worksheets(out).Cells(brow, 1) = wb.Worksheets("Template").Cells(3, 3)
ThisWorkbook.Worksheets(out).Cells(brow, 2) = wb.Worksheets("Template").Cells(2, 3)
lLastRow = wb.Worksheets("Calculation").Cells(Rows.Count, 3).End(xlUp).Row
lLastRowCol = ThisWorkbook.Worksheets("Build").Cells(Rows.Count,1).End(xlUp).Row
For k = 2 To lLastRowCol
ThisWorkbook.Worksheets(out).Cells(brow, 1) = wb.Worksheets("Template").Cells(3, 3)
ThisWorkbook.Worksheets(out).Cells(brow, 2) = wb.Worksheets("Template").Cells(2, 3)
Col = wb.Worksheets("Calculation").Rows(2).Find("31.12.2018").Column
ThisWorkbook.Worksheets(out).Cells(brow, 3) = wb.Worksheets("Calculation").Cells(2, Col)
Set Target =ThisWorkbook.Worksheets(out).Range(ThisWorkbook.Worksheets(out).Cells(brow, 4),
ThisWorkbook.Worksheets(out).Cells(brow, 4 + lLastRow - 4))
Set Source = wb.Worksheets("Calculation").Range(wb.Worksheets("Calculation").Cells(4, Col), wb.Worksheets("Calculation").Cells(lLastRow, Col))
Source.Copy
Target.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=True
brow = brow + 1
Next k
Object undefined is the most common mistake, and also filetring for non-found values is also not working (not presented in a code above)