表格(OrderForm)資料會自動轉移到OrderData sheet
在表格中的Case type 是drop down list 有Red, White,Mixed
請問一下如何令Quantity根據前面的Case type 轉移到OrderData sheet
因為表格資料現在只會順序地轉移到工作表
如果case type �堛瑪龠竣ㄕP了,那不會match 工作表中的redno, white no, mixed no 的數目
可能我的表達不清楚,但請高手幫忙
這份excel是大學的assignment
[attach]19502[/attach]
[attach]19503[/attach]
[attach]19504[/attach]
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#luhproth
Thanks so much!
unfortunately, I just tried to run it out, but it's still not working
可不可explain一下它的運作?
因為我不太明白這code有什麼意思
Sorry for any inconvenient for explain to me!作者: luhpro 時間: 2014-11-9 21:23
本帖最後由 luhpro 於 2014-11-9 21:52 編輯
回復 3#hildaliu
Dim iI% ' 定義iI為Integer(整數)變數
Dim lTRow& ' 定義lTRow為Long(長整數)變數
Dim rTar As Range ' 定義rTar為儲存格指標
Dim shSou As Worksheet ' 定義shSou為工作表指標
Set shSou = Sheets("OrderForm") ' 設定指標shSou指向OrderForm工作表
With Sheets("OrderData") ' 設定系統預設指標 . 的標的, 底下以 . 開頭的物件或變數中, 其 . 代表OrderData工作表,直到 End With 為止, Cells指令用於表示儲存格, 其格式為 Cells(列號,欄號)
lTRow = .Cells(Rows.Count, 2).End(xlUp).Row + 1 ' 設定lTRow的值等於 .(即OrderData工作表) 中第2(即B)欄的最底下一個有資料儲存格的列號,
' Cells(Rows.Count, 2)=B欄最末列, .End(xlUp) 往上找第一個有資料的儲存格, .Row 取得其列號
For iI = 17 To 19 ' 設定 iI(此處用於列號)的初值為17, 接著執行後續指令,遇到Next時,先將iI加1後再返回此行執行,迴圈內指令重複執行直到 iI 大於 To 後面的數字(本例為19),再接續執行Next後的指令
Set rTar = shSou.Cells(iI, 3) ' 設定rTar=shSou(即OrderForm工作表)的第3(即C)欄第iI列儲存格
Select Case rTar ' 底下將依據 rTar 的值做分支處理
Case "Red" ' 當rTar="Red"時執行底下的指令直到 Case 或 End Select
.Cells(lTRow, 2) = rTar.Offset(, 2) ' 設定OrderData工作表的 B欄第lTRow列=rTar向右位移兩欄(即OrderForm工作表的E欄第iI列儲存格)
Case "Mixed" ' 當rTar="Mixed"時執行底下的指令...
.Cells(lTRow, 4) = rTar.Offset(, 2) ' 同上 D欄第lTRow列=...
End Select ' 選擇性分支指令結束
Next ' 繼續執行下一個 For 指令條件判斷, 以決定是否繼續執行迴圈內的指令
End With ' With 區塊結束,系統預設指標.的標的指向解除,若上層還有.的指向定義,從之.作者: hildaliu 時間: 2014-11-10 04:20
回復 4#luhpro
Finally,i got it and the code is totally working!
Thanks for your explanation !!
Thanks so much!!!