所以我遇到了一些麻烦,希望有人可以提供帮助,我试图模拟天气。
我试图计算excel中示例数据集中的分类数据之间发生某些交互的次数:
Sunny
Sunny
Cloudy
P-Cloudy
Sunny
Rainy
Cloudy
Sunny
Sunny
Etc...
所以第一天阳光充足,第二天阳光充足,第三天阴天等等。我如何计算每种天气类型变化的次数,即
Sunny to Sunny 2
Sunny to P-Cloudy 0
Sunny to Cloudy 1
Sunny to Rainy 1
Cloudy to P-Cloudy 1
Cloudy to Sunny 1
Cloudy to Rainy 0 Etc..
非常感谢任何帮助。
答案 0 :(得分:0)
Row A B C D E F G
1 Today Tomorrow
2 Sunny =A3 Sunny Cloudy P-Cloudy Rainy
3 Sunny =A4 Sunny =COUNTIFS(a:a,$D3,b:b,E$2) =COUNTIFS(a:a,$D3,b:b,F$2) =COUNTIFS(a:a,$D3,b:b,G$2) =COUNTIFS(a:a,$D3,b:b,H$2)
4 Cloudy =A5 Cloudy =COUNTIFS(a:a,$D4,b:b,E$2) =COUNTIFS(a:a,$D4,b:b,F$2) =COUNTIFS(a:a,$D4,b:b,G$2) =COUNTIFS(a:a,$D4,b:b,H$2)
5 P-Cloudy =A6 P-Cloudy =COUNTIFS(a:a,$D5,b:b,E$2) =COUNTIFS(a:a,$D5,b:b,F$2) =COUNTIFS(a:a,$D5,b:b,G$2) =COUNTIFS(a:a,$D5,b:b,H$2)
6 Sunny =A7 Rainy =COUNTIFS(a:a,$D6,b:b,E$2) =COUNTIFS(a:a,$D6,b:b,F$2) =COUNTIFS(a:a,$D6,b:b,G$2) =COUNTIFS(a:a,$D6,b:b,H$2)
7 Rainy =A8
8 Cloudy =A9
9 Sunny =A10
10 Sunny
我希望这会有所帮助。 :)
好的我不想重写这个但是所有列引用我会让它们绝对($ A:$ A& $ B:$ B)只是为了使复制和粘贴更容易。
据说C列中的垂直天数列表是今日列,而行2列表是转换到下一天的天气
答案 1 :(得分:0)
Sub model_weather()
lastrow = Worksheets("Sheet1").Cells(Rows.Count, 1).End(xlUp).Row - 1
For i = 1 To lastrow
Cells(i, 1) = Trim(Cells(i, 1))
Cells(i, 2).Value = Cells(i, 1) & " to " & Cells(i + 1, 1)
Cells(i, 3).Value = Cells(i, 1) & " to " & Cells(i + 1, 1)
Next
Range("C1:C" & lastrow).Sort Key1:=Range("C1:C" & lastrow), Order1:=xlAscending, Header:=xlNo
temp = 1
For i = 1 To lastrow
If Cells(i, 3) = Cells(i + 1, 3) Then
temp = temp + 1
Else: temp = 1
End If
Cells(i, 4) = temp
Next
Range("C1:D" & lastrow).Select
Selection.Sort Key1:=Range("C1"), Order1:=xlAscending, _
Key2:=Range("D1"), Order2:=xlAscending, _
Header:=xlNo, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
x = 1
For i = 1 To lastrow
If Cells(i, 3) <> Cells(i + 1, 3) Then
Cells(x, 6) = Cells(i, 3)
Cells(x, 7) = Cells(i, 4)
x = x + 1
End If
Next
End Sub