ªð¦^¦Cªí ¤W¤@¥DÃD µo©«

[µo°Ý] ¤ñ¸û¸ê®Æ-§Q¥ÎVBAµ{¦¡¤ñ¸û¨â­Ó¸ê®ÆÀɮרðµ­pºâ

[µo°Ý] ¤ñ¸û¸ê®Æ-§Q¥ÎVBAµ{¦¡¤ñ¸û¨â­Ó¸ê®ÆÀɮרðµ­pºâ

³Â·Ð¦U¦ì¤j¤j¡G
¥H¤U¤£ª¾¦³½Ö·|©O¡H¥i¥H±Ð§Ú¶Ü¡H
ÀÉ®×A
³W®æ  ¼Æ¶q
AAA  20
BBB   35
CCC  42
DDD 10
ÀÉ®×B
³W®æ  ¼Æ¶q
AAA  20
BBB   30
CCC  46
DDD 10
´N¬O¦³¨â­ÓÀɮפº®e¤À§O¦p¤W¡A§Æ±æ¯à°÷«ö¤@­Ó«ö¶s¡A
1.¥ý±N¨â­ÓÀɮפÀ§O©ñ¦b¦P¤@Àɮפ£¦Pªº¤u§@ªí
2.¦A±N¤ñ¸ûµ²ªG©ñ¦b²Ä¤T­Ó¤u§@ªí¡AÅã¥Ü¦p¤U¡G
³W®æ  ¼Æ¶q    ³W®æ  ¼Æ¶q    ³W®æ  ®t²§¼Æ
AAA  20       AAA  20       AAA       0
BBB   30       BBB   35       BBB        5  (Àx¦s®æ¥Î¬õ¦âÅã¥Ü)
CCC  42       CCC  46       CCC     -6  (Àx¦s®æ¥Î¬õ¦âÅã¥Ü)
DDD 10       DDD 10       DDD      0

¦^´_ 1# amychlo

±Nµ{¦¡½X©ñ¦b·J¾ãªº¬¡­¶Ã¯¤@¯ë¼Ò²Õ
  1. Sub ·J¾ã()
  2. Set d = CreateObject("Scripting.Dictionary")
  3. fd = ThisWorkbook.Path & "\" '3­ÓÀɮשñ¦b¦P¥Ø¿ý¤¤
  4. 'fd="D:\"  '«ü©wA¡BB2Àɮתº¦s©ñ¥Ø¿ý
  5. fs = Array("A.xls", "B.xls")
  6. d("³W®æ") = "¼Æ¶q"
  7. For Each f In fs
  8.    With Workbooks.Open(fd & f)
  9.       With .Sheets(1)
  10.       i = i + 1
  11.       .UsedRange.Copy ThisWorkbook.Sheets(i).[A1]
  12.       With ThisWorkbook.Sheets(i)
  13.           For Each a In .Range(.[A2], .[A2].End(xlDown))
  14.              If IsEmpty(d(a.Value)) Then d(a.Value) = a.Offset(, 1) Else d(a.Value) = a.Offset(, 1) - d(a.Value)
  15.           Next
  16.       End With
  17.       End With
  18.       .Close
  19.     End With
  20. Next
  21. With Sheets(3)
  22.    .[A1].Resize(d.Count, 1) = Application.Transpose(d.keys)
  23.    .[B1].Resize(d.Count, 1) = Application.Transpose(d.items)
  24. End With
  25. End Sub
½Æ»s¥N½X
¾Ç®üµL²P_¤£®¢¤U°Ý

TOP

¤j¤j½Ð°Ý¤@¤U¡G
1.±z©Ò»¡ªº¤@¯ë¼Ò²Õ¬O¦bModule¤U¶Ü¡H
2.©ñ¦b¼Ò²Õ¤U¡A¤£¥Î«Ø«ö¶sIJµo¶Ü¡H
¤£¦n·N«ä¡I
¦]¬°­è±µÄ²vba©Ò¥H¤@¤ÁÁÙ¦bºN¯Á¤¤¡A
½Ð±z¦h¦h«ü±ÐÅo¡I
·P®¦

TOP

¤j¤j½Ð°Ý¤@¤U¡G
1.±z©Ò»¡ªº¤@¯ë¼Ò²Õ¬O¦bModule¤U¶Ü¡H
2.©ñ¦b¼Ò²Õ¤U¡A¤£¥Î«Ø«ö¶sIJµo¶Ü¡H
¤£¦n·N«ä¡I
¦] ...
amychlo µoªí©ó 2013-2-23 19:35


1. ¹ï
2.¤£«Ø«ö¶sªº¸Ü,
¦bmodule¤WÂI¤W¥ô¦ó¤@¦æ, «ökeyboard "F5"Áä ¥i
©Î¦bexcel­¶­± "¶}µo¤H­û"µæ³æ->¥¨¶°->¿ï¤Wsub ->°õ¦æ
À´±oµo°Ý,µª®×´N·|¦b¨ä¤¤

¤µ¤éの¤@¬íは  ©ú¤éにない
http://kimbalko-chi.blogspot.com
http://kimbalko.blogspot.com

TOP

¦^´_ 2# Hsieh

·P®¦¤j¤jªº¦^À³¡I
(3/2)«á¨Ó´£°Ýªº°ÝÃD¬O¡G
A.xls
¶µ¦¸  ³W®æ  ³æ¦ì  ³æ»ù  ¼Æ¶q
   1     AA1   pcs    10    300
   2     AB2   pcs     20   35
   3     AC1   pcs     18   0
   4     AD2   pcs     10   52
   5     AE3    pcs     15   200
B.xls
¶µ¦¸  ³W®æ  ³æ¦ì  ¼Æ¶q
   1     A1     pcs    300
   2     B2     pcs     40
   3     E3     pcs     150
1.­º¥ý¥ý±NA¡BB¨â­ÓÀɮפÀ§O©ñ¦b¦P¤@­ÓÀɮסB¤£¦Pªº¤u§@ªí
    A¡BB¨â­ÓÀɮתº[³W®æ]¬O¬Û¦Pªº¡A
   ¥u¬O·íªì¦b«ØAÀɮ׮ɦb¨C¤@­Ó³W®æªº²Ä¤@½X¥[¤F¤@½X"A"¡A
   ¨ä¾l«á¤èªº³£¬Û¦P¡C
2.¦A±N¤ñ¸ûµ²ªG©ñ¦b²Ä¤T­Ó¤u§@ªí¡AÅã¥Ü¦p¤U¡G
   (§Æ±æ¦b²Ä¤T­Ó¤u§@ªí¤]¯à±NA¡BB¨âÀÉ®×Åã¥Ü¥X¨Ó)
³W®æ  ¼Æ¶q    ³W®æ  ¼Æ¶q     ³W®æ  ®t²§¼Æ(B.xla-A.xls)
A1     300     A1     300      A1       0
B2     35        B2     40         B2       5  
C1     0          E3      150      C1       0  
D2    52                                 D2       -52
E3     200                               E3       -50

TOP

¦^´_ 5# amychlo
¬Q¤Ñ¦]¬°½×¾ÂªººÏºÐ°}¦C¥X°ÝÃD¡A¿ò¥¢¤F¸ê®Æ¡A­«·s¦^´_
  1. Sub ·J¾ã()
  2. Dim Ar()
  3. Set d = CreateObject("Scripting.Dictionary")
  4. fd = ThisWorkbook.Path & "\" '3­ÓÀɮשñ¦b¦P¥Ø¿ý¤¤
  5. 'fd="D:\"  '«ü©wA¡BB2Àɮתº¦s©ñ¥Ø¿ý
  6. fs = Array("A.xls", "B.xls")
  7. d("³W®æ") = "¼Æ¶q"
  8. For Each f In fs
  9.    With Workbooks.Open(fd & f)
  10.       With .Sheets(1)
  11.       i = i + 1
  12.       ReDim Preserve Ar(2, s)
  13.       Ar(0, s) = "³W®æ": Ar(1, s) = "¼Æ¶q"
  14.       s = s + 1
  15.       .UsedRange.Copy ThisWorkbook.Sheets(i).[A1]
  16.       With ThisWorkbook.Sheets(i)
  17.           For Each a In .Range(.[B2], .[B2].End(xlDown))
  18.              If IsEmpty(d(Right(a, 2))) Then d(Right(a, 2)) = a.Offset(, IIf(i = 1, 3, 2)) Else d(Right(a, 2)) = a.Offset(, IIf(i = 1, 3, 2)) - d(Right(a, 2))
  19.              ReDim Preserve Ar(2, s)
  20.              Ar(0, s) = Right(a, 2): Ar(1, s) = a.Offset(, IIf(i = 1, 3, 2)).Value
  21.              s = s + 1
  22.           Next
  23.           Sheets(3).[A1].Offset(, (i - 1) * 2).Resize(s, 2) = Application.Transpose(Ar)
  24.           Erase Ar: s = 0
  25.       End With
  26.       End With
  27.       .Close
  28.     End With
  29. Next
  30. With Sheets(3)
  31.    .[E1].Resize(d.Count, 1) = Application.Transpose(d.keys)
  32.    .[F1].Resize(d.Count, 1) = Application.Transpose(d.items)
  33. End With
  34. End Sub
½Æ»s¥N½X
¾Ç®üµL²P_¤£®¢¤U°Ý

TOP

¦^´_ 6# Hsieh

¤j¤j¡G
·P®¦±zªº¦^´_¡I
¦ý§Ú¸Õ¤F´X¤ÑÁÙ¬O§ï¤£¥X§Ú­nªºª¬ªp¡A
©Ò¥H²{¦b´N§â§Úªº­ì©lÀÉÀ£ÁY¤W¶Ç¡A
¦A³Â·Ð±z¬Ý¬Ý¡I
·P®¦¡I
A.rar (6.78 KB)       B.rar (4.78 KB)

TOP

¦^´_ 7# amychlo
¸Õ¸Õ¬Ý
  1. Sub ·J¾ã()
  2. Dim Ar()
  3. Set d = CreateObject("Scripting.Dictionary")
  4. fd = ThisWorkbook.Path & "\" '3­ÓÀɮשñ¦b¦P¥Ø¿ý¤¤
  5. 'fd="D:\"  '«ü©wA¡BB2Àɮתº¦s©ñ¥Ø¿ý
  6. fs = Array("A.xls", "B.xls")
  7. d("³W®æ") = "¼Æ¶q"
  8. For Each f In fs
  9.    With Workbooks.Open(fd & f)
  10.       With .Sheets(1)
  11.       i = i + 1
  12.       ReDim Preserve Ar(2, s)
  13.       Ar(0, s) = "³W®æ": Ar(1, s) = "¼Æ¶q"
  14.       s = s + 1
  15.       .UsedRange.Copy ThisWorkbook.Sheets(i).[A1]
  16.       With ThisWorkbook.Sheets(i)
  17.           For Each a In .Range(.[B2], .[B2].End(xlDown))
  18.           mystr = Mid(a, 1 / (i / 2))
  19.              If IsEmpty(d(mystr)) Then d(mystr) = a.Offset(, IIf(i = 1, 7, 2)) Else d(mystr) = a.Offset(, IIf(i = 1, 7, 2)) - d(mystr)
  20.              ReDim Preserve Ar(2, s)
  21.              Ar(0, s) = mystr: Ar(1, s) = a.Offset(, IIf(i = 1, 7, 2)).Value
  22.              s = s + 1
  23.           Next
  24.           Sheets(3).[A1].Offset(, (i - 1) * 2).Resize(s, 2) = Application.Transpose(Ar)
  25.           Erase Ar: s = 0
  26.       End With
  27.       End With
  28.       .Close 0
  29.     End With
  30. Next
  31. With Sheets(3)
  32.    .[E1].Resize(d.Count, 1) = Application.Transpose(d.keys)
  33.    .[F1].Resize(d.Count, 1) = Application.Transpose(d.items)
  34. End With
  35. End Sub
½Æ»s¥N½X
¾Ç®üµL²P_¤£®¢¤U°Ý

TOP

¦^´_ 8# Hsieh

¤j¤j¡G·P®¦±z¡I
¤j­P¤W¬O¥i¥H¤F¡A
¦ý¬O°õ¦æ®Éµo¥Í
[°õ¦æ¶¥¬q¿ù»~'9'
°}¦C¯Á¤Þ¶W¥X½d³ò]
¦A«ö(°»¿ù)«á
´Nµo²{¼Ò²Õµ{¦¡«ü¦V²Ä24¦C¡A

©Ò¥H¤£ª¾¹D³o¤@¦C¬O¦³¤°»ò¥Î³~©O¡H
³Â·Ð±zÅo¡I·P®¦

TOP

¦^´_ 9# amychlo

³o¥y¬O±N°}¦C¼g¤J¤u§@ªí
¦¹¥y·|µo¥Í¶W¥X°}¦C¯Á¤Þ¿ù»~¥u¥i¯àµo¥Í¦bSheets(3)
¦³¥i¯à§Aªº¬¡­¶Ã¯¨Ã¨S¦³3­Ó¥H¤Wªº¤u§@ªí¦s¦b
¾Ç®üµL²P_¤£®¢¤U°Ý

TOP

        ÀR«ä¦Û¦b : §Ú­Ì­n°µ¦nªÀ·|ªºÀô«O¡A¤]­n°µ¦n¤º¤ßªºÀô«O¡C
ªð¦^¦Cªí ¤W¤@¥DÃD