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

[µo°Ý] ¦p¦ó¶×¤JEXCEL¸ê®Æ?

[µo°Ý] ¦p¦ó¶×¤JEXCEL¸ê®Æ?

¦U¦ì¥ý¶i,½ÐÀ°¦£¸£¤O¿EÀú: ¥ýÁÂÁ¤F!

§Úªº»Ý¨D¦p¤U,±NPI_PO¸ê®Æ§¨ªº¨C¤@­ÓÀɮ׸ê®Æ¶×¤JPI_PO RecordsÀɮפ¤?¥Î¥¨¶°µ{¦¡©Î¥Î¨ç¼Æ¯à§ì¨ú§Ú­nªº¸ê®Æ?(Àɮפwªþ¤W)
»Ý¶×¤JªºÄæ¦ì¬°PI/PO sheet¤¤ªº¦X­pª÷ÃB¤Î¼Æ¶q
1        ±NEXCELªí®æ¤¤¦³PI/POªº¦X­pª÷ÃB¤Î¼Æ¶q¶ñ¤J"PI_PO Records"Àɮפ¤
2        ±NEXCELªí®æ¤¤¥u¦³POªº¦X­pª÷ÃB¤Î¼Æ¶q¶ñ¤J"PI_PO Records"Àɮפ¤
    VBA TEST 5.zip (107.4 KB)
        PI_PO¸ê®Æ§¨¤¤ÀɮׯS©Ê:
1        PI_PO¸ê®Æ§¨¤¤ªº©Ò¦³EXCELÀɮפ¤TOTALÄæ¦ì¤¤ªº©Ò¦³¦X­p¸ê®Æ(¥]§t¼Æ¶q/ª÷ÃB)
2        ¦³¨ÇÀÉ®×KEY-IN¬°"TOTAL",¦³¨Ç¬O"TOTAL:"
3        EXCELÀÉ"TOTAL"¦r¼Ë,©T©w¦bAÄæ
4        ¦X­pÄæ¦ì¼Æ¶q¤Îª÷ÃBªº¦C¼Æ«h¤£©T©w,°ß¤@©T©wªº¬O¼Æ¶q«á·|¦³"PCS"¦r¼Ë,¦Óª÷ÃB«e·|¦³"¹ô§O"(US/USD/HKD¡Kµ¥)
5        EXCELÀɨ̫Ȥá°Ï¤À¦³©Ò¤£¦P,¦³¨ÇÀɮצ³"PI"»P"PO" sheet,¦³¨Ç«h¥u¦³"PO" sheet
6        PI_POªºEXCELÀɮ榡¬° .xls  or  .xlsx(§Ú¥u©ñ¤F3ºØ®×¨Ò)
7        PI_PO RecordsªºFÄæFile Name¬O¯S§Okey-in¤W¥hªº(¤£ª¾¦³¨S¦³À°§U?),³q±`¥u·|¦³A:EÄæ

¦^´_ 43# Hsieh

¦Ñ¤j,

40¼Óªºµ{¦¡§ì¨ìªº¸ê®Æ¤ñ¸û§¹¾ã.
³o¦¸­×§ïªºÁöµM¥i¥H±N#REF! ³oºØÀx¦s®æªº¸ê®Æ¨ÌµM¶ñ¤JPI_PO Records¤¤¤£·|¦A°±º¢¤£°õ¦æ,¦ý¦³¨ä¥L¥H©¹§ì±o¨ìªº¸ê®Æ²{¦b«oµLªk§ì¨ì!
¯à§_¥H40¼Óªºµ{¦¡¬°°ò¦,¥u­n¤p¤pªº­×§ï¤£·|¦]¬°¶Ã½Xªº¼Æ­È?(¦p«e­±©Ò´£#REF! )¦Ó°±º¢¤£°õ¦æ?

TOP

¦^´_ 42# oobird

¤j¤j,
ªGµM¤£·|¦A¥X²{¸ß°Ýªº¹ï¸Ü®Ø¤F.

TOP

¥»©«³Ì«á¥Ñ Hsieh ©ó 2012-5-19 14:49 ½s¿è

¦^´_ 41# PJChen
  1. Sub get_value()
  2. Dim Sh As Worksheet, a As Range, Ar(), B As Range, B1 As Range
  3. Set d = CreateObject("Scripting.Dictionary")
  4. Application.ScreenUpdating = False
  5. Application.DisplayAlerts = False
  6. fd = ThisWorkbook.Path & "\" & "PI_PO\"
  7. fs = Dir(fd & "*xls*")
  8. Do Until fs = ""
  9. With Workbooks.Open(Filename:=fd & fs, UpdateLinks:=False)
  10. n = Split(fs, " ")(0)
  11. s = InStr(n, "BCM") + 3
  12. fn = Mid(n, s)
  13.    For Each Sh In .Sheets
  14.       With Sh
  15.       If Trim(.Name) <> "PO" And Trim(.Name) <> "PI" Then GoTo 10
  16.       ay = .UsedRange.Value
  17.       For i = 1 To UBound(ay)
  18.          mystr = ""
  19.          For j1 = 1 To UBound(ay, 2)
  20.             mystr = IIf(mystr = "", UCase(Trim(.Cells(i, j1).Text)), mystr & Chr(10) & UCase(Trim(.Cells(i, j1).Text)))
  21.          Next
  22.          If Trim(Replace(mystr, Chr(10), "")) Like "TOTAL*PCS?*" Then
  23.          ak = Split(mystr, "PCS")
  24.          ax = Split(Trim(ak(0)), Chr(10))
  25.          ap = Split(Trim(ak(1)), Chr(10))
  26.                d(Trim(.Name) & "¼Æ¶q") = ax(UBound(ax) - 1)
  27.                d(Trim(.Name) & "ª÷ÃB") = ap(2)
  28.                Exit For
  29.          End If
  30.       Next
  31.       End With
  32. 10
  33.     Next
  34.     ReDim Preserve Ar(y)
  35.     Ar(y) = Array(fn, d("PI¼Æ¶q"), d("PIª÷ÃB"), d("PO¼Æ¶q"), d("POª÷ÃB"), fs)
  36.     y = y + 1
  37.     .Close
  38.     d.RemoveAll
  39. End With
  40. fs = Dir
  41. Loop
  42. Sheets("Records").[A2].Resize(y, 6) = Application.Transpose(Application.Transpose(Ar))
  43. Application.ScreenUpdating = True
  44. Application.DisplayAlerts = True
  45. End Sub
½Æ»s¥N½X
¾Ç®üµL²P_¤£®¢¤U°Ý

TOP

Application.DisplayAlerts = False
Application.AskToUpdateLinks = False
³o¨â¦æ¤@°_¥Î¸Õ¸Õ

TOP

¦^´_ 40# Hsieh
¤j¤H,
Àɮפ¤ª÷ÃB©Î¼Æ¶q­Y¥X²{        ¿ù»~°T®§,¨Ò:#REF!,¦p¦óÅý¥¦¨ÌµM¶ñ¦bPI_PO RecordsÀɮפ¤?§Ú¨Æ«á¦A¥h¬d¬Ý°ÝÃD´N¦n¤F,§_«hµ{·|°±º¢¤£°õ¦æ!

¦^´_ 38# oobird
oobird¤j¤j:
¦]¬°±z¼gªºµ{¦¡§¹¥þ¤£·|Åã¥Ü¥¿¦brun­þ¤@µ§,©Ò¥H¨C·í¥X²{¥H¤Uªº¹ï¸Ü®Ø,§Ú¯u¤£ª¾¬O¤°»ò°ÝÃD?¥B¦]¬°¦³«Ü¦hÀɮצ³³oºØ±¡§Î(§ÚµLªk±oª¾¬O­þ¤@­Ó?),¯à§_´N¥u¬OÅýµ{¦¡¦Û°Ê¿ï¾Ü¤£­n§ó·s¥B¦Û°Ê©¹¤U°õ¦æ?§_«hµ{¦¡¦brun®É¥²¶·¤@ª½µ¥¦b¹q¸£«e«ö"¤£§ó·s"!

TOP

¦^´_ 39# PJChen
¤@¦C¤¤¦P®É¦s¦bTOTAL»PPCS§@¬°§PÂ_¼Ð·Ç
  1. Sub get_value()
  2. Dim Sh As Worksheet, a As Range, Ar(), B As Range, B1 As Range
  3. Set d = CreateObject("Scripting.Dictionary")
  4. Application.ScreenUpdating = False
  5. Application.DisplayAlerts = False
  6. fd = ThisWorkbook.Path & "\" & "PI_PO\"
  7. fs = Dir(fd & "*xls*")
  8. Do Until fs = ""
  9. With Workbooks.Open(Filename:=fd & fs, UpdateLinks:=False)
  10. n = Split(fs, " ")(0)
  11. s = InStr(n, "BCM") + 3
  12. fn = Mid(n, s)
  13.    For Each Sh In .Sheets
  14.       With Sh
  15.       If Trim(.Name) <> "PO" And Trim(.Name) <> "PI" Then GoTo 10
  16.       ay = .UsedRange.Value
  17.       For i = 1 To UBound(ay)
  18.          mystr = UCase(Join(Application.Index(ay, i)))
  19.          If InStr(mystr, "TOTAL") > 0 And InStr(mystr, "PCS") > 0 Then
  20.             For j = 1 To UBound(ay, 2)
  21.                If ay(i, j) = "PCS" Then d(Trim(.Name) & "¼Æ¶q") = ay(i, j - 1): yn = True
  22.                If IsNumeric(ay(i, j)) And yn = True Then d(Trim(.Name) & "ª÷ÃB") = ay(i, j): yn = False: Exit For
  23.             Next
  24.          End If
  25.       Next
  26. 20
  27.       End With
  28. 10
  29.     Next
  30.     ReDim Preserve Ar(y)
  31.     Ar(y) = Array(fn, d("PI¼Æ¶q"), d("PIª÷ÃB"), d("PO¼Æ¶q"), d("POª÷ÃB"), fs)
  32.     y = y + 1
  33.     .Close
  34.     d.RemoveAll
  35. End With
  36. fs = Dir
  37. Loop
  38. Sheets("Records").[A2].Resize(y, 6) = Application.Transpose(Application.Transpose(Ar))
  39. Application.ScreenUpdating = True
  40. Application.DisplayAlerts = True
  41. End Sub
½Æ»s¥N½X
¾Ç®üµL²P_¤£®¢¤U°Ý

TOP

¦^´_ 38# oobird
¦^´_ 35# Hsieh
¦Ñ¤j,½Ð°Ý§A¬O§_¦^µª§Ú²Ä37¼Óªº°ÝÃD?­Y¬Oªº¸Ü:
Âk¨s°_¨Ó¬OÀɮפӦh¤£¦P®æ¦¡©Ò³y¦¨ªº°ÝÃD,­Y¬OTOTALªº°ÝÃD,§Ú·Q«Ü¦hÄæ¦ì³£·|¥Î³o­Ó¦r,­Y§Ú²Î¤@¥u±Ä¥Î"TOTAL:"(¬O¦³«_¸¹ªº),«h¥H¤U³o2­Óµ{¦¡¤W§ÚÀ³¸Ó¦p¦ó­×§ï?¸Ó¥¦¥u¦b¬Ý¨ì"TOTAL:"ªº±¡§Î¤U¤~§@°Ê§@?(¤G­Óµ{¦¡¦U¦³¥¦¦n¥Î¥Îªº¦a¤è,§Ú³£·Q­×§ï¥¦)
  1. Sub get_value()
  2. Dim Sh As Worksheet, a As Range, Ar(), B As Range, B1 As Range
  3. Set d = CreateObject("Scripting.Dictionary")
  4. Application.ScreenUpdating = False
  5. Application.DisplayAlerts = False
  6. fd = ThisWorkbook.Path & "\" & "2011 PI_PO\"
  7. fs = Dir(fd & "*xls*")
  8. Do Until fs = ""
  9. With Workbooks.Open(Filename:=fd & fs, UpdateLinks:=False)
  10. n = Split(fs, " ")(0)
  11. s = InStr(n, "BCM") + 3
  12. fn = Mid(n, s)
  13.    For Each Sh In .Sheets
  14.       With Sh
  15.       If Trim(.Name) <> "PO" And Trim(.Name) <> "PI" Then GoTo 10
  16.       For Each c In .Range("A:B").SpecialCells(xlCellTypeConstants)
  17.         If c Like "TOTAL*" Then Set a = c: Exit For
  18.       Next
  19.       If Not a Is Nothing Then
  20.       Set B = a.EntireRow.Find("pcs")
  21.       Set B1 = a.EntireRow.Find("*", after:=B)
  22.       
  23.       If Not B Is Nothing Then
  24.         d(Trim(.Name) & "¼Æ¶q") = B.Offset(, -1)
  25.         c1 = a.EntireRow.Find("*", after:=B1)
  26.         d(Trim(.Name) & "ª÷ÃB") = c1
  27.       End If
  28.       End If
  29.       Set a = Nothing
  30.       End With
  31. 10
  32.     Next
  33.     ReDim Preserve Ar(y)
  34.     Ar(y) = Array(fn, d("PI¼Æ¶q"), d("PIª÷ÃB"), d("PO¼Æ¶q"), d("POª÷ÃB"), fs)
  35.     y = y + 1
  36.     .Close
  37.     d.RemoveAll
  38. End With
  39. fs = Dir
  40. Loop
  41. Sheets("Records").[A2].Resize(y, 6) = Application.Transpose(Application.Transpose(Ar))
  42. Application.ScreenUpdating = True
  43. Application.DisplayAlerts = True
  44. End Sub
½Æ»s¥N½X
  1. Sub get_value_F()
  2.     Dim a As Range, arr(1 To 5)
  3.     Application.ScreenUpdating = False    'Ãö³¬¿Ã¹õ°{Ã{
  4.     For Each a In Range([f2], [f2].End(4))    '¦bf2¥H¤Uªº¸ê®Æ½d³ò´`Àô
  5.         If Application.CountA(Rows(a.Row)) = 1 Then    'a:eÄæ¤w¦³¼g¤J¸ê®Æ´N¸õ¹L
  6.             Application.DisplayAlerts = False    'Ãö³¬¶}±Ò®Éªº¹ï¸Ü¤è¶ô
  7.             fb = ThisWorkbook.Path & "\2011 PI_PO\" & a    '±q"PI_PO¸ê®Æ§¨"¨ú¸ô®|
  8.             Set wk = GetObject(fb)    '­I´º¶}±Ò¸Ó¸ô®|ÀÉ®×
  9.             Sh = Array("PI", "PO")    '¨â­Ó¤u§@ªí¦W
  10.             On Error Resume Next    '²¤¹L¿ù»~
  11.             For s = 0 To 1
  12.                 Set mysheet = wk.Sheets(Sh(s))    '¤u§@ªíÅܶq
  13.                 If Err.Number = 0 Then    '¦p¤£µo¥Í¿ù»~(¦³³o­Ó¤u§@ªí)
  14.                 mysheet.AutoFilterMode = False '¨ú®ø¿z¿ï
  15.                     mysheet.[a:b].Replace "TOTAL:", "TOTAL", xlWhole    '§â±a¤À¸¹ªºTOTAL§ï¦¨¤£±a¤À¸¹
  16.                     r = mysheet.[a:b].Find("TOTAL", , , 1, xlByRows).Row    '¦bAB¨âÄæ´M§ä"TOTAL"
  17.                     c = mysheet.Cells(r, 15).End(1).Column    '¨úTOTAL¨º¤@¦æªº³Ì¥kÄæ(§Yª÷ÃB)
  18.                     arr(1) = Split(a, " ")(0) '¨úfÄæ²Ä¤@­ÓªÅ®æ¥H«eªº¦r¦ê
  19.                     arr(s * 2 + 2) = mysheet.Cells(r, c - 3).Value    '¨ú³Ì¥kÄæ´î3Ä檺¼Æ¦r
  20.                     arr(s * 2 + 3) = mysheet.Cells(r, c).Value    '¨ú³Ì¥kÄ檺¼Æ¦r
  21.                 End If
  22.                 Err.Clear    '²M°£¿ù»~
  23.             Next
  24.            Cells(a.Row, 1).Resize(1, 5) = arr   '¼g¤JÀx¦s®æ
  25.             Erase arr
  26.             wk.Close 0            'Ãö³¬¥´¶}ªºÀɮפ£Àx¦s
  27.         End If
  28.     Next
  29. End Sub
½Æ»s¥N½X

TOP

¥»©«³Ì«á¥Ñ oobird ©ó 2012-5-18 22:23 ½s¿è

³o´X­ÓÀɮתº°ÝÃD¬O¨âÄæ³£¦³"TOTAL"
For Each c In .Range("A:B").SpecialCells(xlCellTypeConstants)
§ï¦¨ For Each c In .Range("A:A").SpecialCells(xlCellTypeConstants)
ÁÙ¬O¦Ñ°ÝÃD¡ABÄæ¤]¦³"TOTAL",¦Ó¥B¦b«e­±¡A¾É­P¿ù»~§PÂ_
§ï¦¨¥u¦bAÄæ´M§ä, ¦ý©p­n«Oµý"TOTAL"¬O¦bAÄæ
¦Ü©óÁÙ¬O·|¥X²{¹ï¸Ü¤è¶ôªº°ÝÃD¡A¨S¹ê»Ú¸I¨ì¤£ª¾¬O¤°»ò±¡ªp¡C

TOP

¦^´_ 35# Hsieh
¤j¤H,

¸ß°Ý§ó·sªº¹ï¸Ü®Ø¤£¦A¥X²{¤F,¦ý¥X²{¤F·sªº¹ï¸Ü®Ø¦p¤U,§Ú±N´X­ÓÀɮפW¶Ç,³Â·Ð§A.
«¬ºA¤£²Å.jpg
VBA TEST 5-answer 4_Hsieh.zip (127.44 KB)

TOP

        ÀR«ä¦Û¦b : ­n§åµû§O¤H®É¡A¥ý·Q·Q¦Û¤v¬O§_§¹¬üµL¯Ê¡C
ªð¦^¦Cªí ¤W¤@¥DÃD