PDA

View Full Version : Solved: Cut and Paste macro



Anomandaris
04-17-2009, 08:27 AM
Hi, its me again, I'm seem to have messed up this simple macro. Basically Any Row with Cell.Value = "SOLD" in Column K should be sent to Sheet2 from Sheet1. (It doesnt have to be the entire Row, I need columns A to L, but entire row is fine too)

any idea why this code isnt working? thanks


Sub fig()
Dim cell As Range
Dim x As Integer
Dim Rng As Range
Dim Row As Range
x = Sheet1.Range("K" & Rows.Count).End(xlUp).Row
Set Rng = Sheet1.Range("K4:K" & x)
For Each cell In Rng
If cell.Value = "SOLD" Then
cell.EntireRow.Cut
Sheet2.Select
Range("A4").Select
Selection.Paste
End If
Next cell
End Sub

mdmackillop
04-17-2009, 10:19 AM
You're pasting everything to the same cell

Sub fig()
Dim cell As Range
Dim x As Long, y As Long
Dim Rng As Range
Dim Row As Range
Dim Tgt As Range

x = Sheet1.Range("K" & Rows.Count).End(xlUp).Row
Set Rng = Sheet1.Range("K4:K" & x)
Set Tgt = Sheet2.Range("A3")
For Each cell In Rng
If cell.Value = "SOLD" Then
y = y + 1
cell.EntireRow.Cut Tgt.Offset(y)
End If
Next cell
End Sub

Anomandaris
04-20-2009, 11:51 PM
thanks a lot buddy