Hi there,
I'm trying to make a macro (in excel 2007) that copies a value if the cell next to it has '1' as value, and then paste it into another sheet, without empty cells. For example:
1 - Value 1
0 - Value 2
1 - Value 3
1 - Value 4
0 - Value 5
Makes:
Value 1
Value 3
Value 4
The following macro is what I think should work, but I keep getting an error 1004 (I don't know the english error discription, but it should be something like 'Method Select of Class Range failed). It then highlights 'rng2.Select'. Can anyone help me with this? Thanks!
I'm trying to make a macro (in excel 2007) that copies a value if the cell next to it has '1' as value, and then paste it into another sheet, without empty cells. For example:
1 - Value 1
0 - Value 2
1 - Value 3
1 - Value 4
0 - Value 5
Makes:
Value 1
Value 3
Value 4
The following macro is what I think should work, but I keep getting an error 1004 (I don't know the english error discription, but it should be something like 'Method Select of Class Range failed). It then highlights 'rng2.Select'. Can anyone help me with this? Thanks!
Code:
Private Sub CommandButton1_Click()
Dim rng1 As Range
Dim rng2 As Range
Sheets("Printen").Activate
ActiveSheet.Range("A:A").Select
Selection.Delete
Sheets("Selecteren").Activate
Set rng2 = Range("A1")
ActiveSheet.Range("C4").Select
Do While IsEmpty(ActiveCell) = False
If Selection.Value = 1 Then
Set rng1 = ActiveCell
ActiveCell.Offset(0, 1).Select
Selection.Copy
Sheets("Printen").Activate
rng2.Select
Selection.PasteSpecial Paste:=xlPasteValues, _
Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Selection.PasteSpecial Paste:=xlPasteFormats, _
Operation:=xlNone, SkipBlanks:=False, Transpose:=False
ActiveCell.Offset(1, 0).Select
Set rng2 = ActiveCell
Sheets("Selecteren").Activate
rng1.Select
End If
ActiveCell.Offset(1, 0).Select
Loop
Application.CutCopyMode = False