Re: [VBA ] 如何做到多筆轉置?
方向應該是這樣,對吧@@
原始 目的
A B C D E F G H A B C D E F G H
1 11 1 11 12 13 14 15
2 12 2 21 22 23 24 25
3 13 3
4 14 4
5 15 5
6 21 6
7 22 7
8 23 8
9 24 9
10 25 10
Private Sub CommandButton1_Click()
Dim RowIndex As Integer, RecIndex As Integer, ColIndex As Integer
Dim Src As String, Dest As String, SrcUBound As Long
SrcUBound = Val(InputBox("請輸入資料數量"))
RowIndex = 0: RecIndex = 1: ColIndex = 0
'開始轉換資料
Do
If ColIndex = 5 Then ColIndex = 0: RecIndex = RecIndex + 1
ColIndex = ColIndex + 1
RowIndex = RowIndex + 1
Src = "A" & RowIndex
Dest = Chr(ColIndex + 64) & RecIndex
Range(Dest).Value = Range(Src).Value
Loop While RowIndex < SrcUBound
'清除原始資料
Src = "A" & (RecIndex + 1)
Dest = "A" & SrcUBound
Range(Src & ":" & Dest).Clear
MsgBox "資料轉換完成,共" & RecIndex & "列資料", vbInformation
End Sub
--
做資料轉換前,原始資料要記得備份
--
▃▅▇▆▄ ▆▂▃ `
逝去感情如何能留住,半點癡情遺留殊不易,██▅▇▄▃ ▇▃▂" .
█████████▃i ▁▄▇
更多悽悽慘慘的遭遇…………██▆▃ █▅▆▃ˍ▄*
◢ ▂█▄▇▅▂▌.
我不知道,王~八~蛋~~! ▂▆███ █▄▃ 。fumizuki。Check。
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 210.58.156.43
討論串 (同標題文章)
完整討論串 (本文為第 2 之 2 篇):
Visual_Basic 近期熱門文章
PTT數位生活區 即時熱門文章