說明:
提醒:
E欄查核結果會依照A欄日期是否為當天往前推30天內(含30天),判斷是否列入計算。
如上例店家『首幅』,如之後未再出現,則等到10/10當天,往前推30天內為9/11~10/10,故9/10第一次出現將不列入計算
,而9/11第一次出現則改顯示為空白、9/17第二次則改顯示為重覆1,以此類推...
E欄查核公式是我目前想到破頭的可能方向,但是錯誤的喔!!!因為驗證結果失敗
所以可能要再請大師們幫幫忙了~~~
測試檔
https://drive.google.com/file/d/1M2hYtaanFctihTRAyV3XuIBrBgR1poLU/view?usp=sharing
這種每天執行結果會不一樣
的題目
我只會用 VBA 做
Sub Macro1()
Dim arrName() As Variant '記錄廠商名稱
Dim arrCount() As Variant '記錄廠商出現次數
arrCnt = 2 '陣列長度
ReDim arrName(1 To arrCnt)
ReDim arrCount(1 To arrCnt)
dStart = DateAdd("D", -30, Now) '開始時間
dEnd = Now '結束時間
inRange = False '是否在範圍中
Debug.Print dStart, dEnd
Range("A1").Select
Do While True
dDate = ActiveCell.Value
sName = ActiveCell.Offset(0, 3).Value
'判斷空白, 結束執行
If dDate = "" Then
Exit Do
End If
'判斷目前是否在範圍中
If (dDate > dStart) And (dDate < dEnd) Then
inRange = True
Else
inRange = False
End If
'若在範圍中則進行重覆判斷
If (inRange) Then
Pos = IsInArray(sName, arrName)
If Pos > 0 Then
If arrCount(Pos) > 0 Then
ActiveCell.Offset(0, 4).Value = "重覆" + Trim(Str(arrCount(Pos)))
Else
ActiveCell.Offset(0, 4).Value = "重覆"
End If
arrCount(Pos) = arrCount(Pos) + 1
Else
arrCnt = arrCnt + 1
ReDim Preserve arrName(1 To arrCnt)
ReDim Preserve arrCount(1 To arrCnt)
arrName(UBound(arrName)) = sName
arrCount(UBound(arrCount)) = arrCount(UBound(arrCount)) + 1
ActiveCell.Offset(0, 4) = ""
End If
Else
ActiveCell.Offset(0, 4) = ""
End If
ActiveCell.Offset(1, 0).Select
Loop
For i = 1 To UBound(arrName)
Debug.Print i, arrName(i), arrCount(i)
Next i
End Sub
Public Function IsInArray(ByVal stringToBeFound As String, ByVal arr As Variant) As Integer
Dim i
For i = LBound(arr) To UBound(arr)
If arr(i) = stringToBeFound Then
IsInArray = i
Exit Function
End If
Next i
IsInArray = -1
End Function
另外,點這裡是我這次鐵人賽唯一的一篇文章,喜歡的話左上角點 Like
什麼!!!不能用巨集
下次請先寫在問題第一列
E1儲存格:
=IF(COUNTIFS($A$2:A2,">="&TODAY()-29,$D$2:D2,D2)>=2,"重覆"&COUNTIFS($A$2:A2,">="&TODAY()-29,$D$2:D2,D2)-1,"")
也可以寫成
=IF(SUMPRODUCT(($A$2:A2>=(TODAY()-29))X($D$2:D2=D2)X1)<2,"","重覆"&SUMPRODUCT(($A$2:A2>=(TODAY()-29))X($D$2:D2=D2)X1)-1)