返回列表 上一主題 發帖

[發問] VBA 迴圈 剪貼排序

[發問] 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

回復 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


VBA迴圈剪貼排序.zip (61.21 KB)

TOP

        靜思自在 : 【時間如鑽石】時間對一個有智慧的人而言,就如鑽石般珍貴;但對愚人來說,卻像是一把泥土,一點價值也沒有。
返回列表 上一主題