麻辣家族討論版版's Archiver

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

[b]回復 [url=http://forum.twbts.com/redirect.php?goto=findpost&pid=108248&ptid=21755]1#[/url] [i]newvbaer[/i] [/b]


   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]

頁: [1]

麻辣家族討論版版為 麻辣學園 網站成員  由 昱得資訊工作室 © Since 1993 所提供