- ©«¤l
- 1447
- ¥DÃD
- 40
- ºëµØ
- 0
- ¿n¤À
- 1471
- ÂI¦W
- 0
- §@·~¨t²Î
- Windows 7
- ³nÅ骩¥»
- Excel 2010 & 2016
- ¾\ŪÅv
- 50
- ©Ê§O
- ¨k
- ¨Ó¦Û
- ¥xÆW
- µù¥U®É¶¡
- 2020-7-15
- ³Ì«áµn¿ý
- 2024-12-5
|
¥»©«³Ì«á¥Ñ Andy2483 ©ó 2022-12-28 15:30 ½s¿è
¦^´_ 1# olisun
ÁÂÁ«e½úµoªí¦¹¥DÃD»P½d¨Ò,ÁÂÁ¦U¦ì«e½ú«ü¾É
«á¾ÇÂǦ¹©«²ß±o«Ü¦hª¾ÃÑ»P¸gÅç,¥Î¥¬ªLÅܼƾã¦X°j°é,»{ÃÑRept()¹Bºâ¦¡.....
¥H¤U°õ¦æ¹Lµ{»P¤ß±oµù¸Ñ½Ð¦U¦ì«e½ú«ü¾É
°õ¦æ«e:
°õ¦æµ²ªG:
Option Explicit
Sub TEST_20221228_2()
Dim Arr, i&, j&, S&, A&(3), B$(3), T As Boolean
'¡ô«Å§iÅܼÆ:Arr¬O³q¥Î«¬ÅܼÆ,(i,j,S)¬Oªø¾ã¼ÆÅܼÆ,(A,B)¬O¤@ºû°}¦C,T¬O¥¬ªLÅܼÆ
Arr = Range([C2], [A65536].End(3))
'¡ô¥OArr¬O¤Gºû°}¦C!¥H[C2]¨ìAÄæ³Ì«á¦³¤º®eÀx¦s®æÈˤJ
Head:
S = IIf(T, 1, 3)
'¡ô¥OS³oªø¾ã¼ÆÅÜ¼Æ¨Ì IIf()§PÂ_TÅܼƬOTure:S=1,TÅܼƬOFalse:S=3
For i = 1 To S
'¡ô³]¶¶°j°é!i±q1¨ìSÅܼÆ
For j = 1 To UBound(Arr)
'¡ô³]¶¶°j°é!j±q1¨ìArr°}¦CÁa¦V³Ì¤j¦C¯Á¤Þ¸¹
If T Then
'¡ô¦pªGTÅܼƬO Ture PS:T¬O ¥¬ªLÅܼÆ,¨äªì©lȬOFalse
B(1) = Arr(j, 1) & Application.Rept(" ", A(1) - Len(Arr(j, 1)))
'¡ô¥O¯Á¤Þ¸¹1ªºB°}¦CȬO j°j°é¦C²Ä1ÄæArr°}¦Cȳs±µ ¼ÆÓ" "ªÅ¥Õ¦r¤¸,
'¼ÆÓ?:¥HRept()¹Bºâ¦¡½Æ»s(¯Á¤Þ¸¹1ªºA°}¦CÈ- j°j°é¦C²Ä1ÄæArr°}¦CȪº¦r¼Æ)Ó" "ªÅ¥Õ¦r¤¸
'https://learn.microsoft.com/zh-tw/office/vba/api/excel.worksheetfunction.rept
B(2) = Arr(j, 2) & Application.Rept(" ", A(2) - Len(Arr(j, 2)))
'¡ôÃþ±À
Arr(j, i) = B(1) & "+" & B(2) & " " & Arr(j, 3)
'¡ô¥Oj°j°é¦Ci°j°éÄæArr°}¦CȬO ¤TÓB°}¦Cȳs±µ"+"©M" "²Å¸¹ªº¦r¦ê
ElseIf A(i) < Len(Arr(j, i)) Then
'¡ô§_«h¦pªGi°j°éA°}¦CÈ < j°j°é¦Ci°j°éÄæArr°}¦Cȸ̪º¦r¼Æ??
A(i) = Len(Arr(j, i))
'¡ô¥Oi°j°éA°}¦CȬO j°j°é¦Ci°j°éÄæArr°}¦Cȸ̪º¦r¼Æ
'(¨D³Ì¤j¦r¼Æ)
End If
Next
Next
If T = False Then T = True: GoTo Head
'¡ô¦pªGTÅܼƬO False,´NÅýTÅܼƬO True,µ{§Ç¸õ¨ì Head¼Ð¥Ü³BÄ~Äò°õ¦æ
[H2].Resize(UBound(Arr), 1) = Arr
'¡ô¥O[H2]ÂX®i¦V¤UArr°}¦CÁa¦V³Ì¤j¦C¯Á¤Þ¸¹¼Æ,¦V¥k¤£ÂX®i,³oÄæÀx¦s®æÈ¥HArr°}¦CÈˤJ
Set Arr = Nothing
Erase A, B
End Sub |
|