Hello everyone,
I've sub that loops through multiple csv files and searches date value in column B (dates in descending order 11/28/2020 14:30 format). Once the date is found aim is to check cell M value of the same row, if it is = "BUY", then to copy/paste data to another (this) workbook. The code is not working. No error messages. initially I thought that it does not copy data, later on I've realized that id does not find searched value. I've posted the same thread at another forum:
https://www.excelforum.com/exc…in-value.html#post5448122
but I was not able to upload attachments there and hence was not able to get help from coders. Tried to change search arguments from xlWhole to xlPart, from xlValues to xlFormulas with no success.
Please find code as it follows below along with attached file with code (MasterFilePriceAnalyser.xlsm) and sample csv file with data I'm looking for (ALRM.csv). File ALRM.cvs extesion had to be changed to .xls as .csv files cannot be uploaded. The code needs to be able to search in csv files. The code is supposed to find row39 and copy/paste range A:O to thisworkbook. I would be helpful for any help.
Sub SearchDate()
Dim wb As Workbook, ws As Worksheet
Dim sDate As Range
Set fso = CreateObject("Scripting.FileSystemObject")
Set fldr = fso.GetFolder("C:\VBA\VBA\To be processed 1\")
Set DestSh = Workbooks("MasterFilePriceAnalyser.xlsm").Worksheets("MasterSheet")
Set destwb = Workbooks("MasterFilePriceAnalyser.xlsm")
Application.ScreenUpdating = False
Application.EnableEvents = False
Application.DisplayStatusBar = True
Application.DisplayAlerts = False
Application.Calculation = xlCalculationManual
With DestSh
.Range("A1").Value = "Symbol"
.Range("B1").Value = "Date"
.Range("C1").Value = "Open"
.Range("D1").Value = "High"
.Range("E1").Value = "Low"
.Range("F1").Value = "Close"
.Range("G1").Value = "Adj. Close"
.Range("H1").Value = "Volume"
.Range("I1").Value = "V/SMA10"
.Range("J1").Value = "Vol/Change%"
.Range("K1").Value = "SMA10"
.Range("L1").Value = "SMA30"
.Range("M1").Value = "Buy/Sell"
.Range("N1").Value = "Close/Change%"
End With
ActiveSheet.Columns.AutoFit
On Error Resume Next
Dim counter As Long
Dim numFiles As Long
numFiles = fldr.Files.Count
counter = 1
For Each wbFile In fldr.Files
Application.StatusBar = "Processing: " & Format(counter / numFiles, "0.0%") & " completed"
If fso.GetExtensionName(wbFile.Name) = "csv" Then
Set wb = Workbooks.Open(wbFile.Path)
Set sDate = wb.worksheets(1).Range("B:B").Find(what:=destwb.Worksheets("Sheet1").Range("B1").Value, LookIn:=xlValues, lookat:=xlWhole)
If sDate <> "" Then
DestRowNumber = DestSh.Cells(Rows.Count, 1).End(xlUp).Row
If sDate.Offset(0, 11).Value = "BUY" Then
DestSh.Rows(DestRowNumber).Range("A1:O1").Value = sDate.EntireRow.Range("A1:O1").Value
End If
Else
End If
wb.Close True
End If
counter = counter + 1
Next wbFile
DestSh.Columns.AutoFit
Application.ScreenUpdating = True
Application.EnableEvents = True
Application.DisplayAlerts = True
Application.CutCopyMode = False
Application.DisplayStatusBar = True
End Sub
Display More