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

VBA ¸ê®Æ·j´M°ÝÃD

VBA ¸ê®Æ·j´M°ÝÃD

§Ú¦³¤@­ÓÃe¤jªº¸ê®Æ®w(¸ê®Æ¤w¶W¥X65536µ§),¦]¬° Excel ªº¤½¦¡¤w¸g¤£¯àº¡¨¬§Úªº»Ý¨D, ©Ò¥H·Q¥H VBA ¸Ñ¨M°ÝÃD

     ½Ð°Ý·í§Ú·Q¥H"½s¸¹"©ÎªÌ¥H"«~¦W"¦A©ÎªÌ·Q¥H"¼t°Ó"·j´M¸ê®Æ, ³o®É VBA ªº»yªk­n¦p¦ó¼¶¼g?
     (·íµM³o3­Ó°ÝÃD¤£¬O¦P¤@®É¶¡¤@°_¶i¦æ)

      VBA»yªk.rar (24.39 KB)

¥»©«³Ì«á¥Ñ singo1232001 ©ó 2023-3-7 10:20 ½s¿è

·PÁ­ìPO ·PÁ¦U¦ì¤j¤j  
³oÃD«Ü¤£¿ù
½m²ß§¹²¦ ªþ¤WÀÉ®×

¶}±Ò"SQL·j´M"¤u§@ªí
´X­Ó²©ö¥\¯à»¡©ú  
1.¥u¦b¦C7¿é¤J ·|¼Ò½k·j¯Á
2.¦C6¦C7³£¿é¤J ·|°Ï¶¡·j¯Á
3.D,E,GÄæ ¦U¬°¤å¦r¼Ò½k·j¯Á ¥iªÅ®æ ¨Ò¦p:A ¥q ¿é¥X A¤½¥q
4.¥þ³¡ªÅ¥Õ ¬°¥þ­¶·j¯Á
5.A~JÄæ ¦P®É¿é¤J ·|and·j¯Á

­­¨î
1.·j´MÀÉ®× »P Àɮרӷ½ ¸ô®|¥Ø«e¨S¦³Àu¤Æ  ¼È©w­n¦b¦P¤@¸ê®Æ§¨©³¤U
2.«Ü¦h¤pbug ¥u¦³°µ¥DÅé´X­Ó¤j¥\¯à ¹L²Óªº«È»s¤Æ¥\¯à»P»Ý¨D ©|¥¼»s§@

Sub ÃöÁä¦r¬d¸ß()
With CreateObject("adodb.connection"): V = Application.Version
If V >= 12 Then V = "Provider=Microsoft.ACE.OLEDB.12.0;Extended Properties=Excel 12.0; "
If V < 12 Then V = "Provider=Microsoft.Jet.OLEDB.4.0;Extended Properties=Excel 8.0; "
.Open V & "Data Source=" & ThisWorkbook.Path & "\SearchData.xlsx"

'excel ½Õ¥Îadodb ¥Î sql ®É Äæ¦ì¦WºÙ¦³"."²Å¸¹ ¶·§ï¬° "#"¸¹
If Cells(7, 1) <> "" And Cells(6, 1) = "" Then sq = sq & " and  [No#] like  '%" & Replace(Cells(7, 1), " ", "%") & "%'"
If Cells(7, 1) <> "" And Cells(6, 1) <> "" Then sq = sq & " and  [No#] between " & Cells(6, 1) & " and " & Cells(7, 1) ' & "'"
If Cells(7, 2) <> "" And Cells(6, 2) = "" Then sq = sq & " and  [Inv#]  like '%" & Replace(Cells(7, 2), " ", "%") & "%'"
If Cells(7, 2) <> "" And Cells(6, 2) <> "" Then sq = sq & " and  [Inv#]  between '" & Cells(6, 2) & "' and '" & Cells(7, 2) & "'"
If IsDate(Cells(7, 3)) Then
If Cells(7, 3) <> "" And Cells(6, 3) = "" Then sq = sq & " and  [Date]  like '%" & Cells(7, 3) & "%'"
If Cells(7, 3) <> "" And Cells(6, 3) <> "" Then sq = sq & " and  Format(Date, 'yyyy-MM-dd')  between '" & Format(Cells(6, 3), "yyyy-MM-dd") & "' and '" & Format(Cells(7, 3), "yyyy-MM-dd") & "'"
End If
If Cells(7, 4) <> "" Then sq = sq & " and  [Supplier] like '%" & Replace(Cells(7, 4), " ", "%") & "%'"
If Cells(7, 5) <> "" Then sq = sq & " and  [Inv#(1)] like '%" & Replace(Cells(7, 5), " ", "%") & "%'"
If Cells(7, 6) <> "" And Cells(6, 6) = "" Then sq = sq & " and  [Part No#] like '%" & Replace(Cells(7, 6), " ", "%") & "%'"
If Cells(7, 6) <> "" And Cells(6, 6) <> "" Then sq = sq & " and  [Part No#]  between '" & Cells(6, 6) & "' and '" & Cells(7, 6) & "'"
If Cells(7, 7) <> "" Then sq = sq & " and  [Prod# Name] like '%" & Replace(Cells(7, 7), " ", "%") & "%'"
If Cells(7, 8) <> "" And Cells(6, 8) = "" Then sq = sq & " and  [Qty]  like '%" & Replace(Cells(7, 8), " ", "%") & "%'"
If Cells(7, 8) <> "" And Cells(6, 8) <> "" Then sq = sq & " and  [Qty]  between " & Cells(6, 8) & " and " & Cells(7, 8)
If Cells(7, 9) <> "" And Cells(6, 9) = "" Then sq = sq & " and  [Amt#]  like '%" & Replace(Cells(7, 9), " ", "%") & "%'"
If Cells(7, 9) <> "" And Cells(6, 9) <> "" Then sq = sq & " and  [Amt#]  between " & Cells(6, 9) & " and " & Cells(7, 9)
If Cells(7, 10) <> "" And Cells(6, 10) = "" Then sq = sq & " and  [Total]  like '%" & Replace(Cells(7, 10), " ", "%") & "%'"
If Cells(7, 10) <> "" And Cells(6, 10) <> "" Then sq = sq & " and  [Total]  between " & Cells(6, 10) & " and " & Cells(7, 10)

If sq <> "" Then sq = Mid(sq, 5, 99999)
If sq <> "" Then sq = "select * from [Data$A1:J] where " & sq
If sq = "" Then sq = "select * from [Data$A1:J] "
Sheets("SQL·j´M").Cells(9, 1).Resize(10000, 10).ClearContents
Sheets("SQL·j´M").Cells(9, 1).CopyFromRecordset .Execute(sq)
.Close: End With
End Sub

Sub ²M°£ÃöÁä¦r()
Sheets("SQL·j´M").Range("a6:J7").ClearContents
End Sub

¸ê®Æ·j´M.zip (54.46 KB)

TOP

¥»©«³Ì«á¥Ñ Andy2483 ©ó 2022-11-28 16:31 ½s¿è

¦^´_ 67# ­ã´£³¡ªL

ÁÂÁ«e½ú±`¥Î¤£¦P¤è¦¡ªºµ{¦¡½XÅý«á½ú¾Ç²ß
1.Application.Goto ['Qty on Hand'!A2]  ¦P  Sheets("Qty on Hand").Activate: [A2].Activate
2.[~!~]ªº³¯­z¤è¦¡·|¦]¬° Qty on Hand ¤§¶¡¦³ªÅ®æ¦ÓµLªk¿ëÃÑ,©Ò¥H­n¥H³æ¤Þ¸¹«e«á¥]¦í

¥H¤W¤ß±o­Y¦³¿ù,½Ð«e½ú¦A«ü¾É!

TOP

¦^´_ 74# Kubi

ÁÂÁ¤F...

TOP

¦^´_ 73# Qin
À£ÁYÀɤº¦³¤U¦C¨â­ÓÀɮסG
1.¥Dµ{¦¡ÀɮסG¸ê®Æ·j´M.xlsm
2.¸ê®Æ®wÀɮסGSearchData.xlsx
¨â­ÓÀÉ®×¥²¶·©ñ¦b¦P­Ó¸ê®Æ§¨¤¤¡C
¸ê®Æ®wÀɮצWºÙ¥²¶·¬°SearchData.xlsx
¸ê®Æ·j´M.rar (38.76 KB)

TOP

¦^´_ 72# Kubi

¹ï,´N¬O­n¤À¶}2­ÓÀÉ.
§A¥i¥H¦AÀ°§Ú¤@¦¸
Åý§Úª¾¹D­n«ç¼Ë¼g¶Ü?
ÁÂÁÂ!!

TOP

¦^´_ 71# Qin

¦Û±q­ã¤j¼ö¤ßÀ°¦£«á¡A§Ú´N¨S¦³¦Afollow¦¹ÃD¤F¡C
¦Ü©ó "Data" (¸ê®Æ®w) & "Search" (·j´M)³o2­ÓÀɤÀ¶}¥Î¡A·N«ä¬O±NData(¸ê®Æ®w)©î¸Ñ¦Ü¥t¥~1­ÓÀɮ׶ܡH
­Y¬O¦p¦¹ªº¸Ü¡A§Úªº¼gªk¥i¯à·|¶}±ÒSearch(·j´M)³o­ÓÀɪº®É­Ô¡A¶¶«KŪ¤JData(¸ê®Æ®w)¦Ü¼È¦s¤u§@ªí¡A§@¬°·j´M¨Ì¾Ú¡C

TOP

¦^´_ 28# Kubi

¦b¦¹¤§«e, §Ú¤@¯u³£¦b¥Î§Aµ¹§Úªºµ{§Ç½X(10¸Uµ§·j´M)
¥¦ªº½T«Ü§Ö¤S«Ü¦n¥Î
¥u¬O§Ú·Q§â "Data" (¸ê®Æ®w) & "Search" (·j´M)³o2­ÓÀɤÀ¶}¥Î.
©Ò¥H§Ú«Ü·Qª¾¹D, §A³o½gµ{¦¡½Xªº³o¾ã¥y»yªk¬O­n¦p¦ó¼gªº?
§Ú·Q¤£¦Pªº»yªk¬O¤£¬O·|¦³¤£¦Pªº¼gªk.
§Ú¥u¬O·Q®³­Ó°Ñ¦Ò¡K


Kubi ¤j¤j,ÁÂÁ§A¡K

TOP

¦^´_ 69# ­ã´£³¡ªL

©¯¦n¦³­ã¤j¤£Â_ªºÀ°¦£, ²Å¦X§Ú»Ý¨Dªºµ{¦¡½X²×©ó¥i¥H¨Ï¥Î¤F¡K
ÁÂÁ§A,·í§Ú»¡¸ê®Æ¤Ó¤j, ·j´M³t«×ºC®É, ¤SÀ°§Ú­«·s¼g¹L¤@½gµ{¦¡½X.
ÁÂÁ§A,¸ò¾Ú§Úªº­n¨DÀ°§Ú­×­×§ï§ï, Åý¥¦¾A¦X§Ú¨Ï¥Î.
ÁÂÁ§A,Á`¦b§Ú¹J¨ì°ÝÃD§ä¤£¨ì­ì¦]®É, ¤´Ä@·N¦hºV´X­Ó¦rµ¹¤©«ü¥Ü©M´£¿ô.
§A¯uªº«Ü´Î«Ü´Î
ÁÙ¦³¯uªº¯uªº¯uªº«Ü¦n¡K

­ã¤j, ÁÂÁ§A!!!





                   **¾Ç¦Ó¤£¹½  »£¤H¤£­Â**

TOP

¦^´_ 68# Qin

§ó¥¿¤U:
With ['Qty on Hand'!I2].Resize(R)
     .NumberFormatLocal = "#,##0;-#,##0"
     .Formula = "=IF(F2=F3,""A"","""")&TEXT(MID(I1,2,99),""0;-0;0;!0"")*(F2=F1)+N(H2)"  '¤½¦¡(1)
     '.Formula = "=IF(F2=F3,""A"","""")&IF(ROW(A1)=1,0,MID(I1,2,99))*(F2=F1)+N(H2)" '¤½¦¡(2)
     '.Formula = "=IF(F2=F3,"""",SUMIF(F:F,F2,H:H))" '¤½¦¡(3)
     .Value = .Value
     .Replace "A*", "", Lookat:=xlPart '¤½¦¡(1)¤Î(2), »Ý¥[³o¤@¦æ
End With

TOP

        ÀR«ä¦Û¦b : ¬Ý§O¤H¤£¶¶²´¡A¬O¦Û¤v­×¾i¤£°÷¡C
ªð¦^¦Cªí ¤W¤@¥DÃD