I'm trying to write a macro that will look at a cell value, and if the value is -1, I want it to delete that cell plus the cell to the left of it. (The two data colums go together)
1)How to I make the If statement saying "If cellval = -1"
2)How do I select that cell (and the one left of it) to delete it?
I want it to search through the entire excel spreadsheet for these negative values. Here is what I have. Can someone tell me what's wrong?
Sub Delete()
Dim Row As Integer
Dim col As Integer
Dim cellname As Integer
col = 2
Row = 2
For col = 2 To 150
For Row = 2 To 340
cellname = Cells(Row, col).Value
If cellname = -1 Then
Range(Cells(Row, col)).Select
Selection.Delete Shift:=xlUp
Range(Cells(Row, col - 1)).Select
Selection.Delete Shift:=xlUp
End If
Row = Row + 1
Next
col = col + 3
Next
End Sub
Thanks!
1)How to I make the If statement saying "If cellval = -1"
2)How do I select that cell (and the one left of it) to delete it?
I want it to search through the entire excel spreadsheet for these negative values. Here is what I have. Can someone tell me what's wrong?
Sub Delete()
Dim Row As Integer
Dim col As Integer
Dim cellname As Integer
col = 2
Row = 2
For col = 2 To 150
For Row = 2 To 340
cellname = Cells(Row, col).Value
If cellname = -1 Then
Range(Cells(Row, col)).Select
Selection.Delete Shift:=xlUp
Range(Cells(Row, col - 1)).Select
Selection.Delete Shift:=xlUp
End If
Row = Row + 1
Next
col = col + 3
Next
End Sub
Thanks!