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

[µo°Ý] VBA loop and select case°ÝÃD (HELP)

¦^´_ 1# hildaliu
¥u°w¹ï¨º3­Ó¸ê®Æªº«þ¨©
  1.   Dim iI%
  2.   Dim lTRow&
  3.   Dim rTar As Range
  4.   Dim shSou As Worksheet
  5.   
  6.   Set shSou = Sheets("OrderForm")
  7.   With Sheets("OrderData")
  8.     lTRow = .Cells(Rows.Count, 2).End(xlUp).Row + 1
  9.     For iI = 17 To 19
  10.       Set rTar = shSou.Cells(iI, 3)
  11.       Select Case rTar
  12.         Case "Red"
  13.           .Cells(lTRow, 2) = rTar.Offset(, 2)
  14.          
  15.         Case "White"
  16.           .Cells(lTRow, 3) = rTar.Offset(, 2)
  17.             
  18.         Case "Mixed"
  19.           .Cells(lTRow, 4) = rTar.Offset(, 2)
  20.       End Select
  21.     Next
  22.   End With
½Æ»s¥N½X

TOP

¥»©«³Ì«á¥Ñ luhpro ©ó 2014-11-9 21:52 ½s¿è

¦^´_ 3# hildaliu
  Dim iI% ' ©w¸qiI¬°Integer(¾ã¼Æ)ÅܼÆ
  Dim lTRow& ' ©w¸qlTRow¬°Long(ªø¾ã¼Æ)ÅܼÆ
  Dim rTar As Range ' ©w¸qrTar¬°Àx¦s®æ«ü¼Ð
  Dim shSou As Worksheet ' ©w¸qshSou¬°¤u§@ªí«ü¼Ð
  
  Set shSou = Sheets("OrderForm") ' ³]©w«ü¼ÐshSou«ü¦VOrderForm¤u§@ªí
  With Sheets("OrderData") ' ³]©w¨t²Î¹w³]«ü¼Ð . ªº¼Ðªº, ©³¤U¥H . ¶}ÀYªºª«¥ó©ÎÅܼƤ¤, ¨ä . ¥NªíOrderData¤u§@ªí,ª½¨ì End With ¬°¤î, Cells«ü¥O¥Î©óªí¥ÜÀx¦s®æ, ¨ä®æ¦¡¬° Cells(¦C¸¹,Äæ¸¹)
    lTRow = .Cells(Rows.Count, 2).End(xlUp).Row + 1 ' ³]©wlTRowªº­Èµ¥©ó .(§YOrderData¤u§@ªí) ¤¤²Ä2(§YB)Äæªº³Ì©³¤U¤@­Ó¦³¸ê®ÆÀx¦s®æªº¦C¸¹,
                                                                                                ' Cells(Rows.Count, 2)=BÄæ³Ì¥½¦C, .End(xlUp) ©¹¤W§ä²Ä¤@­Ó¦³¸ê®ÆªºÀx¦s®æ, .Row ¨ú±o¨ä¦C¸¹

    For iI = 17 To 19 ' ³]©w iI(¦¹³B¥Î©ó¦C¸¹)ªºªì­È¬°17, ±µµÛ°õ¦æ«áÄò«ü¥O,¹J¨ìNext®É,¥ý±NiI¥[1«á¦Aªð¦^¦¹¦æ°õ¦æ,°j°é¤º«ü¥O­«½Æ°õ¦æª½¨ì iI ¤j©ó To «á­±ªº¼Æ¦r(¥»¨Ò¬°19),¦A±µÄò°õ¦æNext«áªº«ü¥O
      Set rTar = shSou.Cells(iI, 3) ' ³]©wrTar=shSou(§YOrderForm¤u§@ªí)ªº²Ä3(§YC)Äæ²ÄiI¦CÀx¦s®æ
      Select Case rTar ' ©³¤U±N¨Ì¾Ú rTar ªº­È°µ¤À¤ä³B²z
        Case "Red" ' ·írTar="Red"®É°õ¦æ©³¤Uªº«ü¥Oª½¨ì Case ©Î End Select
          .Cells(lTRow, 2) = rTar.Offset(, 2)  ' ³]©wOrderData¤u§@ªíªº  BÄæ²ÄlTRow¦C=rTar¦V¥k¦ì²¾¨âÄæ(§YOrderForm¤u§@ªíªºEÄæ²ÄiI¦CÀx¦s®æ)
         
        Case "White" ' ·írTar="White"®É°õ¦æ©³¤Uªº«ü¥O...
          .Cells(lTRow, 3) = rTar.Offset(, 2) ' ¦P¤W CÄæ²ÄlTRow¦C=...
            
        Case "Mixed" ' ·írTar="Mixed"®É°õ¦æ©³¤Uªº«ü¥O...
          .Cells(lTRow, 4) = rTar.Offset(, 2) ' ¦P¤W DÄæ²ÄlTRow¦C=...
      End Select ' ¿ï¾Ü©Ê¤À¤ä«ü¥Oµ²§ô
    Next ' Ä~Äò°õ¦æ¤U¤@­Ó For «ü¥O±ø¥ó§PÂ_, ¥H¨M©w¬O§_Ä~Äò°õ¦æ°j°é¤ºªº«ü¥O
  End With ' With °Ï¶ôµ²§ô,¨t²Î¹w³]«ü¼Ð.ªº¼Ðªº«ü¦V¸Ñ°£,­Y¤W¼hÁÙ¦³.ªº«ü¦V©w¸q,±q¤§.

TOP

        ÀR«ä¦Û¦b : «Î¼e¤£¦p¤ß¼e¡C
ªð¦^¦Cªí ¤W¤@¥DÃD