- ©«¤l
- 8
- ¥DÃD
- 3
- ºëµØ
- 0
- ¿n¤À
- 11
- ÂI¦W
- 0
- §@·~¨t²Î
- Window 8
- ³nÅ骩¥»
- OFFICE 2007
- ¾\ŪÅv
- 10
- ©Ê§O
- ¤k
- µù¥U®É¶¡
- 2014-11-7
- ³Ì«áµn¿ý
- 2015-3-11
|
[µo°Ý] VBA loop and select case°ÝÃD (HELP)
ªí®æ(OrderForm)¸ê®Æ·|¦Û°ÊÂಾ¨ìOrderData sheet
¦bªí®æ¤¤ªºCase type ¬Odrop down list ¦³Red, White,Mixed
½Ð°Ý¤@¤U¦p¦ó¥OQuantity®Ú¾Ú«e±ªºCase type Âಾ¨ìOrderData sheet
¦]¬°ªí®æ¸ê®Æ²{¦b¥u·|¶¶§Ç¦aÂಾ¨ì¤u§@ªí
¦pªGcase type ùتº¿ï¶µ¤£¦P¤F¡A¨º¤£·|match ¤u§@ªí¤¤ªºredno, white no, mixed no ªº¼Æ¥Ø
¥i¯à§Úªºªí¹F¤£²M·¡¡A¦ý½Ð°ª¤âÀ°¦£
³o¥÷excel¬O¤j¾Çªºassignment
CT5002 14-15-001CaneyScopelLiu2.zip (38.83 KB)
- Sub TransferDetails()
- '
- ' TransferDetails Macro
- ' This Macro will make a record of the current details in the order form.
- '
- ' Keyboard Shortcut: Ctrl+Shift+T
- '
-
-
- Sheets("OrderData").Select
-
- 'This IF statement will determine whether or not there is a value in the first row of the database and will paste the data accordingly
-
- If IsEmpty(ActiveSheet.Range("A2")) Then
-
- Range("A2").Select
-
- Else
-
- Sheets("OrderForm").Select
- Sheets("OrderData").Select
- Range("A1").Select
- Selection.End(xlDown).Select
- ActiveCell.Offset(1, 0).Range("A1").Select
-
- End If
-
- Sheets("OrderForm").Select
- Range("D14").Select
- Selection.Copy
- Sheets("OrderData").Select
- Selection.PasteSpecial Paste:=xlPasteValues
- ActiveCell.Offset(0, 1).Range("A1").Select
-
- ' Forloop starts here
- Sheets("OrderForm").Select
-
- Dim Winetype As Integer
- Dim RWM As String
- RWM = ("RWM")
- For Winetype = 1 To 3
- ' LOOP ONE
- ' This section places the Wine Type Into the RWM Cell for referencing
- ' 2.1
- '2.1.1
-
- Sheets("OrderForm").Select
-
- ' 2.1.2
-
- '2.1.2.1
- Range("C17").Select ' <--- C17 = Base Cell
-
- '2.1.2.2
- ActiveCell.Offset(0, 0).Range("A1").Select ' <--- No Change Due to First Iteration
-
- '2.1.3
- '2.1.3.1
- Selection.Copy
- '2.1.3.2.
- Sheets("Price&GiftInfo").Select
- Range("RWM").Select
- Selection.PasteSpecial Paste:=xlPasteValues
- '2.2
- '2.2.1
- Sheets("OrderForm").Select
-
- '2.2.2
- ActiveCell.Offset(0, 2).Select
-
- '2.2.3
- Selection.Copy
-
- '2.3
- '2.3.1.
-
- Sheets("OrderData").Select
- ActiveCell.Select ' <---- No current movement as First Iteration
-
- '2.3.2
- Select Case RWM
-
- Case Is = "Red"
- ActiveCell.Offset(0, 0).Select
-
- Case Is = "White"
- ActiveCell.Offset(0, 1).Select
-
- Case Is = "Mixed"
- ActiveCell.Offset(0, 2).Select
-
- End Select
-
- '2.3.3
- Selection.PasteSpecial Paste:=xlPasteValues
-
- Next
-
- For Winetype = 3 To 3
-
-
-
-
-
-
- '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
-
- ' LOOP TWO
- '2.1
-
- '2.1.1
- Sheets("OrderForm").Select
-
- '2.1.2
-
- '2.1.2.1
- Range("C17").Select
-
- '2.1.2.2
- ActiveCell.Offset(1, 0).Range("A1").Select ' <---- Second iteration = Move one down
-
- '2.1.3
- '2.1.3.1
- Selection.Copy
- '2.1.3.2.
- Sheets("Price&GiftInfo").Select
- Range("RWM").Select
- Selection.PasteSpecial Paste:=xlPasteValues
-
- '2.2
- '2.2.1
- Sheets("OrderForm").Select
-
- '2.2.2
- ActiveCell.Offset(0, 2).Select
-
- '2.2.3
- Selection.Copy
-
- '2.3
- '2.3.1.
- Sheets("OrderData").Select
-
- ActiveCell.Offset(0, 1).Select ' <---- Second Iteration = Move One Across
-
- '2.3.2
-
- Select Case RWM
-
- Case Is = "Red"
- ActiveCell.Offset(0, -1).Select
-
- Case Is = "White"
- ActiveCell.Offset(0, 0).Select
-
- Case Is = "Mixed"
- ActiveCell.Offset(0, 1).Select
-
- End Select
-
- '2.3.3
- Selection.PasteSpecial Paste:=xlPasteValues
-
-
- Next
-
- For Winetype = 3 To 3
-
-
-
-
-
- '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
-
- ' LOOP THREE
- '2.1
- '2.1.1
- Sheets("OrderForm").Select
-
- '2.1.2
-
- '2.1.2.1
- Range("C17").Select
-
- '2.1.2.2
- ActiveCell.Offset(2, 0).Range("A1").Select ' <---- Third iteration = Move two down
-
- '2.1.3
- '2.1.3.1
- Selection.Copy
- '2.1.3.2.
-
- Sheets("Price&GiftInfo").Select
- Range("RWM").Select
- Selection.PasteSpecial Paste:=xlPasteValues
-
- '2.2
- '2.2.1
- Sheets("OrderForm").Select
-
- '2.2.2
- ActiveCell.Offset(0, 2).Select
-
- '2.2.3
- Selection.Copy
-
-
- '2.3
- '2.3.1.
- Sheets("OrderData").Select
-
- ActiveCell.Offset(0, 1).Select ' <---- Third Iteration = Move Two Across
-
- '2.3.2
-
- Select Case RWM
-
- Case Is = "Red"
- ActiveCell.Offset(0, -2).Select
-
- Case Is = "White"
- ActiveCell.Offset(0, -1).Select
-
- Case Is = "Mixed"
- ActiveCell.Offset(0, 0).Select
-
- End Select
-
- '2.3.3
- Selection.PasteSpecial Paste:=xlPasteValues
-
- Next Winetype
-
-
-
-
- ' Forloop ends here
- ActiveCell.Offset(0, 1).Select
-
- Sheets("OrderForm").Select
- Range("E23").Select
- Application.CutCopyMode = False
- Selection.Copy
- Sheets("OrderData").Select
- Selection.PasteSpecial Paste:=xlPasteValues
- ActiveCell.Offset(0, 1).Range("A1").Select
-
- Sheets("OrderForm").Select
- Range("E25:F25").Select
- Application.CutCopyMode = False
- Selection.Copy
- Sheets("OrderData").Select
- ActiveCell.Select
- Selection.PasteSpecial Paste:=xlPasteValues
- ActiveCell.Offset(0, 1).Range("A1").Select
-
- Sheets("OrderForm").Select
- Range("F21").Select
- Application.CutCopyMode = False
- Selection.Copy
- Sheets("OrderData").Select
- Selection.PasteSpecial Paste:=xlPasteValues
- ActiveCell.Offset(0, 1).Range("A1").Select
-
- Sheets("OrderForm").Select
- Range("H17").Select
- Application.CutCopyMode = False
- Selection.Copy
- Sheets("OrderData").Select
- Selection.PasteSpecial Paste:=xlPasteValues
- ActiveCell.Offset(0, 1).Range("A1").Select
-
- Sheets("OrderForm").Select
- Range("H19").Select
- Application.CutCopyMode = False
- Selection.Copy
- Sheets("OrderData").Select
- Selection.PasteSpecial Paste:=xlPasteValues
- ActiveCell.Offset(0, 1).Range("A1").Select
-
- Sheets("OrderForm").Select
- Range("H21").Select
- Application.CutCopyMode = False
- Selection.Copy
- Sheets("OrderData").Select
- Selection.PasteSpecial Paste:=xlPasteValues
- ActiveCell.Offset(0, 1).Range("A1").Select
-
- Sheets("OrderForm").Select
- Range("H23").Select
- Application.CutCopyMode = False
- Selection.Copy
- Sheets("OrderData").Select
- Selection.PasteSpecial Paste:=xlPasteValues
- ActiveCell.Offset(0, 1).Range("A1").Select
-
- Sheets("OrderForm").Select
- Range("H25").Select
- Application.CutCopyMode = False
- Selection.Copy
- Sheets("OrderData").Select
- Selection.PasteSpecial Paste:=xlPasteValues
- ActiveCell.Offset(0, 1).Range("A1").Select
-
- Sheets("OrderForm").Select
- Range("H27").Select
- Application.CutCopyMode = False
- Selection.Copy
- Sheets("OrderData").Select
- Selection.PasteSpecial Paste:=xlPasteValues
- ActiveCell.Offset(0, 1).Range("A1").Select
-
- ' Updates the ref no.
-
- Sheets("Price&GiftInfo").Select
- Application.CutCopyMode = False
-
- Range("A21").Select
- ActiveCell.FormulaR1C1 = "='OrderData'!R[18]C[-13]+1"
-
- Sheets("OrderForm").Select
- Range("H14").Select
- ActiveCell.FormulaR1C1 = "='OrderData'!R[7]C[-7]+1"
- Selection.Copy
-
- Sheets("OrderData").Select
- Selection.PasteSpecial Paste:=xlPasteValues
- Application.CutCopyMode = False
- Selection.Copy
-
- Sheets("Price&GiftInfo").Select
- Selection.PasteSpecial Paste:=xlPasteValues
- Application.CutCopyMode = False
- Sheets("OrderData").Select
- ActiveCell.Select
-
- End Sub
½Æ»s¥N½X |
|