Я написал несколько скриптов VBA для поиска диапазона дат в списке, он может найти даты, но по какой-то причине он не может соответствовать их целевому диапазону. Я тестировал целевой диапазон с помощью vlookup, который возвращает совпадение, но код .find, похоже, не работает одинаково.Excel VBA - не могу .find date string в диапазоне
Например, Sourcecolumnvalue получит дату в своем диапазоне (скажем, 01/02/2015). Значение sourcecolumn будет отражать это, но, похоже, не может найти это в целевом диапазоне, как указано в строке .find.
Я что-то не так с этим кодом?
Sub Finddates()
Dim SourceColumnValue As String, sourcerow As String, targetrow As String
Dim M As Long, O As Long, TargetValue As Long, actualsourcerow As Long, actualtargetrow As Long, actualtargetcolumn As Long, sourcedateposition As Long
TargetValue = dumpsheet.Cells(rows.Count, 1).End(xlUp).row
sourcedateposition = dumpsheet.Cells(rows.Count, 5).End(xlUp).row
'Loop Source Column
For F = 1 To sourcedateposition
SourceColumnValue = dumpsheet.Cells(F, 5).Value
'Get Target Column Match to Source
Set TargetColumnRange = dumpsheet.Range("G2:G" & TargetValue).Find(What:=SourceColumnValue, _
LookIn:=xlValues, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows)
'if a match is found
If Not TargetColumnRange Is Nothing Then
TargetColumnRange.Value = SourceColumnValue
For O = 1 To dumpsheet.Range("A2:A" & rows.Count).End(xlUp).row
Sourcename = ActiveCell(O, 1).Value
sourcerow = ActiveCell(O, 2).Value
targetrow = ActiveCell(O, 3).Value
actualsourcerow = CInt(sourcerow)
actualtargetrow = CInt(targetrow)
actualtargetcolumn = CInt(TargetColumn)
CapexTargetSheet.Activate
Cells(actualtargetrow, actualtargetcolumn).Value = CapexSourceSheet.Cells(actualsourcerow, F).Value
Next O
End If
Next F
End Sub
смог опубликовать образец файла для нас работать с Вы? – brettdj