假設你在Cell E2
提供最新嘗試以下操作:
Sub Demo()
Dim rFound As Range, rng As Range, foundRng As Range
Dim strName1 As String, strName2 As String
Dim count As Long, LastRow As Long
Set rng = Range("A:A")
On Error Resume Next
'assign strings to be searched
strName1 = "GA_RE_EM_DEL"
strName2 = "GA_RE_DA_DEL"
'loop two times to find two strings "GA_RE_EM_DEL" and "GA_RE_DA_DEL"
For i = 1 To 2
If i = 1 Then
strName = strName1
Else
strName = strName2
End If
'find the string in Column A
With rng
Set rFound = .Find(What:=strName, After:=.Cells(1, 1), LookIn:=xlValues, LookAt:=xlWhole)
If Not rFound Is Nothing Then
FirstAddress = rFound.Address
Do
'if string found compare the date
If rFound.Offset(0, 1) >= DateValue(Range("E2").Value) Then
If i = 1 Then
Set foundRng = rFound
End If
Exit Do
Else
Set rFound = .FindNext(rFound)
End If
Loop While Not rFound Is Nothing And rFound.Address <> FirstAddress
End If
End With
Next i
On Error GoTo 0
'adding values
If Not foundRng Is Nothing And Not rFound Is Nothing Then
rFound.Offset(0, 2).Value = rFound.Offset(0, 2).Value + foundRng.Offset(0, 2).Value
foundRng.Offset(0, 2).Value = 0
Else
MsgBox "No Data Found"
End If
End Sub
是的,這是可以做到的,但你可能不會讓某人爲你寫信。你試過什麼了? – TheEngineer
是的,可以做到。請閱讀[我如何提出一個好問題](http://stackoverflow.com/help/how-to-ask)以及[如何創建最小,完整和可驗證示例]的幫助主題(http ://stackoverflow.com/help/mcve) –