標題:
[發問]
VBA 迴圈 剪貼排序
[打印本頁]
作者:
newvbaer
時間:
2019-5-14 08:18
標題:
VBA 迴圈 剪貼排序
請問各位高手下面是計劃想用VBA判段讓EXCEL表中mapping為“1"的所對應的“name"欄位資訊貼至另一個工作表(alex)裡,
其中0的跳過, 只貼mapping 欄位是1的對應的“name"欄位資訊, 但是下面的語法是可判斷mapping為“1"的所對應的“name"欄位資訊, 但是只能跳著顯示alex, apple, lindia,無法依序排列
請問VBA該如何修改?考慮過雙迴圈是否能解決 , 但是不知如何寫
麻煩協助 感謝
name gender age mapping
alex m 21 1
apple f 34 1
zoe f 556 0
kelly f 76 0
lindia f 76 1
ikea m 98 0
alex
apple
lindia
Sub looptest()
Dim counter As Long
For counter = 2 To 7
If Cells(counter, 4) = 1 Then
Cells(counter, 1).Select
Selection.Copy
Sheets("alex").Select
Cells(counter, 1).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
End If
Sheets("工作表1").Select
Next
End Sub
作者:
kim223824
時間:
2019-5-19 16:36
回復
1#
newvbaer
Sub looptest()
Dim counter As Long
Sheets("alex").Select
ROW1 = Cells(Rows.Count, "A").End(xlUp).Row
Range(Cells(2, 1), Cells(ROW1, 4)).ClearContents
Sheets("¤u§@ªí1").Select
ROW2 = Cells(Rows.Count, "A").End(xlUp).Row
k = 2
For counter = 2 To ROW2
If Cells(counter, 4) = 1 Then
Range(Cells(counter, 1), Cells(counter, 4)).Copy Sheets("alex").Cells(k, 1)
k = k + 1
End If
Next
Sheets("¤u§@ªí1").Select
End Sub
[attach]30634[/attach]
歡迎光臨 麻辣家族討論版版 (http://forum.twbts.com/)