ç´æ¥ç»VBA代ç å§ï¼VBA æä½æ¥éª¤ï¼ 1ã æå¼ä½ è¦å¤çç表ï¼è¯·å¤çåä¸å®å¤ä»½ä½ çæ°æ®è¡¨ï¼ï¼2ãæä½ALT + F11 ï¼åå»ThisWorkbookï¼å¨åºç°ççé¢ç²è´´ä»£ç ï¼è§ä¸å¾ï¼
3ãç²è´´å¥½ä»£ç åï¼æF5ï¼æè
ç´æ¥ç¹å» æâéç¨âåæ ·ä¸æ¹é£ä¸ªå°ä¸è§å½¢ï¼ï¼ç¶åéçç»æã
4ãè¿è¡ç»æå¦ä¸å¾ï¼
æåï¼ç±äºä¸ç¥éä½ çæ°æ®éï¼æ´ä¸ªæ°æ®è½å¤ççåå§ä¸º 1000 è¡ï¼å¦æä½ çæ°æ®è¶
è¿1000è¡ï¼è¯·åèç³»æãæè
ä½ èªè¡ä¿®æ¹ä»£ç ä¸â1000âçå°æ¹ã
åæ
æ示ï¼å¤çæ°æ®åï¼è¯·æ³¨ææ°æ®å¤ä»½ã
Sub ReSort()
Dim i As Integer
For i = 2 To 1000
If Cells(i, 1) <> "" And Cells(i, 1) <> Cells(i - 1, 1) Then
Dim j As Integer
For j = 4 To 1000 Step 2
If Cells(2, j) = "" Then
Cells(2, j) = Cells(i, 1)
Exit For
End If
Next j
End If
Next i
Dim i2 As Integer
For i2 = 2 To 1000
If Cells(i2, 1) <> "" Then
Dim j2 As Integer
For j2 = 2 To 1256 Step 2
If Cells(i2, 1) = Cells(2, j2) Then
If Cells(2, j2 + 1) = "" Then
Cells(2, j2 + 1) = Cells(i2, 2)
Exit For
End If
If Cells(2, j2 + 1) <> "" Then
Dim n As Integer
For n = 1 To 201
If Cells(2 + n, j2 + 1) = "" And Cells(n + 1, j2 + 1) <> "" Then
Cells(n + 2, j2) = Cells(i2, 1)
Cells(n + 2, j2 + 1) = Cells(i2, 2)
Exit For
End If
Next n
End If
Exit For
End If
Next j2
End If
Next i2
End Sub