abhinav023
New Member
- Joined
- Jul 29, 2014
- Messages
- 1
Hi
I'm trying to write a code so that excel would go through each cell in a range and if the cell value is equal to "inputbox entered value" it will write ok and delete everything else.
The problem is that if i'm assigning any other value in adjacent column or changing font types etc. then it works fine. but if i use the delete row option, it skips a few item. Please find below the code i wrote:-
Sub LoopA()
Dim cell As Range
Dim Portionnumber As Integer
Dim Msg As String
Portionnumber = InputBox("Enter the portion to be billed")
If Portionnumber <> 1001 And Portionnumber <> 1002 And Portionnumber <> 1003 And Portionnumber <> 1004 Then
Msg = "Enter a valid Portion number i.e. 1001/1002/1003/1004"
MsgBox Msg
Exit Sub
End If
For Each cell In Range("A:A")
If IsEmpty(cell) Then
Exit Sub
ElseIf cell.Value = "Portion" Then
cell.Offset(0, 1).Activate
ActiveCell.Value = "Type"
ElseIf cell.Value = Portionnumber Then
cell.Offset(0, 1).Activate
ActiveCell.Value = "OK"
Else: cell.EntireRow.Delete
End If
Next cell
End Sub
I'm trying to write a code so that excel would go through each cell in a range and if the cell value is equal to "inputbox entered value" it will write ok and delete everything else.
The problem is that if i'm assigning any other value in adjacent column or changing font types etc. then it works fine. but if i use the delete row option, it skips a few item. Please find below the code i wrote:-
Sub LoopA()
Dim cell As Range
Dim Portionnumber As Integer
Dim Msg As String
Portionnumber = InputBox("Enter the portion to be billed")
If Portionnumber <> 1001 And Portionnumber <> 1002 And Portionnumber <> 1003 And Portionnumber <> 1004 Then
Msg = "Enter a valid Portion number i.e. 1001/1002/1003/1004"
MsgBox Msg
Exit Sub
End If
For Each cell In Range("A:A")
If IsEmpty(cell) Then
Exit Sub
ElseIf cell.Value = "Portion" Then
cell.Offset(0, 1).Activate
ActiveCell.Value = "Type"
ElseIf cell.Value = Portionnumber Then
cell.Offset(0, 1).Activate
ActiveCell.Value = "OK"
Else: cell.EntireRow.Delete
End If
Next cell
End Sub