create list

kasbac

Active Member
Joined
Jan 2, 2008
Messages
344
Hi there

I need held writing a macro that will start out by looking at each line in coulm C. If the line equals "xxx" coulm A and D in the same line should be copy/paste special values in to the worksheet "zzz" in coulmn A and B starting in line 2.

Hope someone will be able to give me a hand?
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Try

Code:
Sub test()
Dim LR As Long, i As Long
LR = Range("C" & Rows.Count).End(xlUp).Row
For i = 1 To LR
    If Range("C" & i).Value = "xxx" Then
        Range("A" & i).Copy
        Sheets("zzz").Range("A" & Rows.Count).End(xlUp).Offset(1).PasteSpecial Paste:=xlPasteValues
        Range("D" & i).Copy
        Sheets("zzz").Range("B" & Rows.Count).End(xlUp).Offset(1).PasteSpecial Paste:=xlPasteValues
    End If
Next i
End Sub
 
Upvote 0
Perhaps

Code:
Sub Macro1()
Dim lst As Long
Dim sh1 As Worksheet
Dim sh2 As Worksheet
Set sh1 = Sheet1
Set sh2 = Sheets("zzz")
lst = sh1.Range("A" & Rows.Count).End(xlUp).Row
    sh1.Range("$A$2:$D$" & lst).AutoFilter Field:=3, Criteria1:="xxx"
    sh1.Range("$A$2:$A$" & lst).SpecialCells(xlCellTypeVisible).Copy
    sh2.Range("A2").PasteSpecial xlPasteValues
    sh1.Range("$D$2:$D$" & lst).SpecialCells(xlCellTypeVisible).Copy
    sh2.Range("B2").PasteSpecial xlPasteValues
    
End Sub
 
Upvote 0
Hi guys

Thanks for the replys!

What changes would I need to do in Peters macro so that the values are pasted in from line 3 an onwards in the "zzz" tab?
 
Upvote 0
Try

Code:
Sub test()
Dim LR As Long, i As Long, LR2 As Long
LR = Range("C" & Rows.Count).End(xlUp).Row
For i = 1 To LR
    If Range("C" & i).Value = "xxx" Then
        LR2 = WorksheetFunction.Min(3, Sheets("zzz").Range("A" & Rows.Count).End(xlUp).Row + 1)
        Range("A" & i).Copy
        Sheets("zzz").Range("A" & LR2).PasteSpecial Paste:=xlPasteValues
        Range("D" & i).Copy
        Sheets("zzz").Range("B" & LR2).PasteSpecial Paste:=xlPasteValues
    End If
Next i
End Sub
 
Upvote 0
hmm not sure excatly whats going on but the macro only seem to transfer the first and last line containing xxx to the zzz tab? these are pasted in from A2 and onwards?
 
Upvote 0
Sorry, it should be

Rich (BB code):
Sub test()
Dim LR As Long, i As Long, LR2 As Long
LR = Range("C" & Rows.Count).End(xlUp).Row
For i = 1 To LR
    If Range("C" & i).Value = "xxx" Then
        LR2 = WorksheetFunction.Max(3, Sheets("zzz").Range("A" & Rows.Count).End(xlUp).Row + 1)
        Range("A" & i).Copy
        Sheets("zzz").Range("A" & LR2).PasteSpecial Paste:=xlPasteValues
        Range("D" & i).Copy
        Sheets("zzz").Range("B" & LR2).PasteSpecial Paste:=xlPasteValues
    End If
Next i
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,613
Messages
6,179,904
Members
452,948
Latest member
Dupuhini

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top