|
|
moving selected cells to another sheet
I have tried 2 methods but I couldn't get either to work.
Basically If the value in Z is TRUE then the whole row should be copied to the sheet Available orders.Code:Sub moveit()
Dim Item2 As Range
With Sheets("Status Report")
Set MyRange = .Range("A7", .Range("A" amp; Rows.Count).End(xlUp))
End With
c = 1
For Each Item In MyRange If Item.Cells(1).Offset(, 26).Value = True Then n = 1 For Each Item2 In Item.EntireRowSheets("available orders").Range("A2").Offset(c, n).Value = Item2.Valuec = c + 1n = n + 1 Next Item2 End If
Next Item
End Sub
This got complicated so I tried an recorded autofilter but that lost the goto visible cells only failed.Code:
Sheets("Status Report").AutoFilter Field:=26, Criteria1:="TRUE"
Sheets("Status Report").Range("I6").Select
Cells.Copy Sheets("Available Orders").Select Range("A2").Select Selection.pastespecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _ False, Transpose:=False
any help on either or both bits of code would be appreciated - and advice on which is the best method as well.
Not tested, but try:
Code:
Sub moveit()
With Sheets("Status Report")
Set MyRange = .Range("A7", .Range("A" amp; Rows.Count).End(xlUp))
End With
c = 0
For Each Item In MyRange If Item.Offset(, 25).Value = True Then Sheets("available orders").Range("A2").Offset(c).EntireRow.Value = Item.EntireRow.Valuec = c + 1 End If
Next Item
End SubTryCode:
Sub a()
Dim LR1 As Long, LR2 As Long, i As Long
LR2 = Sheets("available orders").Range("A" amp; Rows.Count).End(xlUp).Row + 1
With Sheets("Status Report") LR1 = .Range("A" amp; Rows.Count).End(xlUp).Row For i = 7 To LR1 If .Range("Z" amp; i).Value = True Then.Rows(i).CopySheets("available orders").Range("A" amp; LR2).PasteSpecial Paste:=xlPasteValuesLR2 = LR2 + 1 End If Next i
End With
Application.CutCopyMode = False
End SubAndrew - you've been a great help today - I really appreciate it.
I almost tried .entirerow.value but I couldn't figure out how I could get the value of an entirerow I figured only a single cell would have a .value.
Thanks also VoG.
Couldn't you use Advanced Filter or Auto Filter?
Both could be done using code, but I'm afraid I don't have time at the moment to either mock up data or write code.
I did try an Autofilter but that stumped me too.
The code I have is clear to me. I understand what its doing and it works in less than a second so I'm happy with it. |
|