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

[µo°Ý] ¨S¦³³]©wª«¥óÅܼƩΠWith °Ï¶ôÅܼÆ

[µo°Ý] ¨S¦³³]©wª«¥óÅܼƩΠWith °Ï¶ôÅܼÆ

¦U¦ì¦n

§Úªºµ{¦¡¦³¶¥¬q¿ù»~''91''ªº°ÝÃD¡A¦ý§Ú¹ê¦b§ä¤£¥X¨Ó­ì¦]¡A
¥u¦n¤W¨Ó¨D±Ð¤F¡C
µ{¦¡½X¦p¤U¡G

Sub Scheduling()
With Worksheets("Scheduling")
    n = .Columns("A").Find("*", SearchOrder:=xlByRows, LookIn:=xlFormulas, SearchDirection:=xlPrevious).EntireRow.Row
    For i = 5 To n Step 2
        ProductID = Worksheets("Scheduling").Cells(i, 3)
            Set d = Sheets("KEYIN").Columns("AH").Find(ProductID, LookIn:=xlValues, lookat:=xlWhole)  '¦b¸ê®Æ®w¤¤·j´M¬Ûµ¥ ®Æ¸¹ ¤§­È
            If Not d Is Nothing Then  ' ¦pªG§ä¨ì¬Ûµ¥¤§­Èªº¸Ü
                Product = Worksheets("KEYIN").Cells(d.Row, d.Column + 1)
            End If
        .Cells(i, 4) = Product
    Next i
End With

Worksheets("M").Activate
    For i = 3 To 23
        For Each od In ActiveSheet.Buttons
           If od.Name = ("Buttons " & i) Then
                od.Delete
           End If
        Next        
        For Each od In ActiveSheet.OLEObjects
           If od.Name = ("CheckBox" & CStr(i)) Or od.Name = ("CheckBoxb" & CStr(i)) Then
                od.Delete
           End If
        Next
        serial = 0
        
        machine = Worksheets("M").Cells(i, 3)
        Set c = Worksheets("Scheduling").Columns("B").Find(machine, LookIn:=xlValues, lookat:=xlWhole) '¦b¸ê®Æ®w¤¤·j´M¬Ûµ¥  ¤§­È
        If Not c Is Nothing Then  ' ¦pªG§ä¨ì¬Ûµ¥¤§­Èªº¸Ü
            firstAddress = c.Address
            serial = 1
            Do
                If Worksheets("Scheduling").Cells(c.Row, 1) = Date And serial = 1 Then                    
                    ProductID = Worksheets("Scheduling").Cells(c.Row, 3)
                    Product = Worksheets("Scheduling").Cells(c.Row, 4)
                    Demand = Worksheets("Scheduling").Cells(c.Row, 5)
                    Operater = Worksheets("Scheduling").Cells(c.Row, 7)
                    Starttime = Worksheets("Scheduling").Cells(c.Row, 9)
                    Worksheets("Scheduling").Cells(c.Row, 11) = 1
                    Range(Worksheets("Scheduling").Cells(c.Row, 1), Worksheets("Scheduling").Cells(c.Row + 1, 9)).ClearContents
                    Worksheets("M").Cells(i, 4) = Product
                    Worksheets("M").Cells(i, 5) = Demand
                    Worksheets("M").Cells(i, 7) = Operater
                    Worksheets("M").Cells(i, 12) = Starttime
                    
                    If Operater > 0 Then
                        SS = Worksheets("M").Cells(i, 1).Top '©Ò¿ï¾Üªº¥Ø¼Ð¦ì§}
                        ll = Worksheets("M").Cells(i, 1).Left
                        Set ob = Worksheets("M").Buttons.Add(ll + 940, SS + 6, 33, 19) '¥[¤J«ö¶s
                        ob.Characters.Text = "§¹¦¨"  '«ü©w«ö¶s¤å¦r
                        ob.OnAction = "scheduleok"     '«ü©w«ö¶s¥¨¶°
                        ob.Name = "Buttons " & i   '«ü©w«ö¶s¦WºÙ

                        S = Worksheets("M").Cells(i, 7).Top '©Ò¿ï¾Üªº¥Ø¼Ð¦ì§}
                        l = Worksheets("M").Cells(i, 7).Left
                        Set ob1 = Worksheets("M").OLEObjects.Add(ClassType:="Forms.CheckBox.1", Link:=False, _
                            DisplayAsIcon:=False, Left:=l, Top:=S + 1, Width:=26, Height:=13)
                            ob1.Name = "CheckBox" & i
                            ob1.Object.Caption = "¤é"
                            ob1.Object.Font.Size = 9
                            ob1.Object.ForeColor = RGB(255, 128, 128)
                            'ob1.Object.AutoSize = True
                            ob1.Object.BackColor = Worksheets("M").Cells(i, 7).Interior.Color
                            'ob1.Object.SpecialEffect = 0

                    End If
                    
                ElseIf Worksheets("Scheduling").Cells(c.Row, 1) = Date And serial = 2 Then
                    ProductID = Worksheets("Scheduling").Cells(c.Row, 3)
                    Product = Worksheets("Scheduling").Cells(c.Row, 4)
                    Worksheets("M").Cells(i, 13) = Product
                End If
                serial = 2
            Set c = Worksheets("Scheduling").Columns("B").FindNext(c)
            Loop While Not c Is Nothing And c.Address <> firstAddress
        End If
         
    Next i
End Sub

ÁٽЦU¦ì°ª¤â­Ì¬Û§U¡I

¦^´_ 1# esperanto


   ¤è«Kªþ­ÓÀɮ׶ܡH³o¼Ë¤j®a¤ñ¸û¦nÀ°§A¬d¬Ý¤@¤U°ÝÃDÂI¡C

TOP

owen06 ¤j¡G

©êºp¡A¦]Àɮצ³¤½¥qªº¸ê®Æ¡A¤£¤è«KªþÀÉ¡C  Orz

§Úµo²{¦pªG§â

Loop While Not c Is Nothing And c.Address <> firstAddress

§ï¦¨

Loop While Not c Is Nothing

¦ü¥G´N¨S°ÝÃD¤F¡H¡I
³o¼Ë¬Ý¨Ó¦n¹³¬O¦]¬°·í FindNext(c) §ä¤£¨ì®É¡Ac¨S¦³­È©Ò¥Hµo¥Í°ÝÃD¡C
¥i¬O§Ú¦b§Oªºµ{¦¡¤¤¤]¬O³o¼Ë¨Ï¥Î FindNext °t¦XDo....Loop¡A³£¨Sµo¥Í°ÝÃD°Ú¡H
§Ú¬O·ÓVBA¸Ìªº»¡©ú½d¨Ò¼gªº¡A
¬°¦ó¦b³o¬qµ{¦¡¤¤·|¦³"¨S¦³³]©wª«¥óÅܼƩΠWith °Ï¶ôÅܼÆ"ªº¿ù»~©O¡H

§Æ±æ¯à¦³¤H«ü±Ð¤p§Ì¡A§Ú¬°¤F³o°ÝÃD¥d¤F1¤Ñ...........Orz

TOP

¥»©«³Ì«á¥Ñ stillfish00 ©ó 2014-6-9 13:39 ½s¿è

¦^´_ 3# esperanto
»¡©ú½d¨Òªºbug§a¡A§Ú·|§â
  1. Loop While Not c Is Nothing And c.Address <> firstAddress
½Æ»s¥N½X
§ï¦¨
  1.     If c Is Nothing Then Exit Do
  2. Loop While c.Address <> FirstAddress
½Æ»s¥N½X
­ì¦]À³¸Ó¬Oloop while ±ø¥ó¤¤¡A
VBA·|§â¨â±ø¥ó¥ý¨D¥X¨Ó¦AAnd°_¨Ó¡A³y¦¨
c.Address <> FirstAddress¥ª¦¡¦bc¬°nothing®É¨D¤£¥X¨Ó¡C

TOP

¦^´_ 4# stillfish00


    ÁÂÁÂstillfish00¤j¤j

         ³o¼Ë¼g½T¹ê¯à¸Ñ¨M°ÝÃD¡A¦ý
               Loop While Not c Is Nothing And c.Address <> firstAddress
         ³o¦æµ{¦¡§Ú¤§«e³£¬O³o¼Ë¼gªº¡A³£¥i¥¿±`¹B§@¡A¬°¦ó¦b³o¬qµ{¦¡¤¤´N·|¥X°ÝÃD©O¡H

TOP

¦^´_ 5# esperanto
À³¸Ó¬O§A¦b§Oªºµ{¦¡¡A¦b§ä¨ìc«á¤£·|§ï±¼cªº­È¡A©Ò¥Hloop¤¤¤£·|¦³c¬°nothing(§ä¤£¨ì¤U¤@­Ó)ªº°ÝÃD¡C
¦ÓVBA»¡©ú½d¨Ò
  1. With Worksheets(1).Range("a1:a500")
  2.     Set c = .Find(2, LookIn:=xlValues)
  3.     If Not c Is Nothing Then
  4.         FirstAddress = c.Address
  5.         Do
  6.             c.Value = 5
  7.             Set c = .FindNext(c)
  8.         Loop While Not c Is Nothing And c.Address <> FirstAddress
  9.     End If
  10.   End With
½Æ»s¥N½X
»¡©ú½d¨Ò¦³c.value = 5 ¡A2³£§ï¬°5«á´N§ä¤£¨ì2¤F
¦Ó§Aªº¨Ò¤l¡A¦³Range(Worksheets("Scheduling").Cells(c.Row, 1), Worksheets("Scheduling").Cells(c.Row + 1, 9)).ClearContents
·|§â§A§äªºmachine²M±¼¡A©Ò¥HFindNext³Ì«á·|¶Ç¦^Nothing

TOP

¦^´_ 6# stillfish00


    ÁÂÁÂstillfish00¤j¤j

                 ¬Ý¨ÓÀ³¸Ó¬O³o¼Ë¤F¡A§Ú¨Sª`·N¨ì»¡©ú½d¨Ò¦³¥ýµ¹c¤@­Ó­È¡C
                 ¤j¤j¯u¬O©ú¹î¬î²@ XD

TOP

        ÀR«ä¦Û¦b : ¯à·F¤£·F¡A¤£¦p­W·F¹ê·F¡C
ªð¦^¦Cªí ¤W¤@¥DÃD