I am trying to set up this macro so it will skip to my next indx
if a cell equals "Not Completed". The problem I am having is that I have to use a different variable and it will just run the For
statement and end the macro.
Do I need a For
statement? If I put Next Indx
after it marks the cell "Not Completed" it will error out.
This what I have set up at the beginning of the macro:
Dim indx As Integer
For indx = 4 To 1000
ordnbr = Sheet1.Cells(indx, 1)
If Trim(ordnbr) = "" Then
Exit For
End If
Before the code below I have my if statements...
Else: Sheet1.Cells(indx, 9) = "Not Competed"
End If
For indx = 4 To 6
If Trim(Status) = "Not Completed" Then
Next indx
End If
I think you want this:
For indx = 4 To 6
If Trim(Status) = "Not Completed" Then
'do nothing, which ultimately causes indx to skip to next in sequence
Else
'put some code here to do something, next in sequence will occur naturally
End If
Next indx
I think the loops are misaligned here.
If Else Endif should be all within the For loop. I revised it a little bit, as follows:
Sub subname()
Dim indx As Integer
a = Sheet1.UsedRange.Rows.Count
For indx = 4 To a
ordnbr = Sheet1.Cells(indx, 1)
If Trim(ordnbr) = "" Then
Else: Sheet1.Cells(indx, 9) = "Not Competed"
End If
Next
End Sub
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.