Help with the Do While Loop

PresidentEvil

New Member
Joined
Jan 2, 2021
Messages
34
Office Version
  1. 2021
  2. 2016
Platform
  1. Windows
Hi,

Code mentioned below has an issue to it. I have two columns ( A & B )

A contains unique IDs
B contains values

I'm using a macro with a loop to update the values in B column for respective IDs. However, the condition to stop the loop is not working. The null value condition is working without a problem but the condition after 'OR' operator is not working. Purpose is to stop the loop when there is a blank in column A or has the text "Access Denied" in column B.

Any hep is highly appreciated.

VBA Code:
Set indexSheet = ActiveSheet
Sheets("Update").Select
irow = 2
A1 = 2
Do While indexSheet.Cells(irow, 1).Value <> vbNullString Or indexSheet.Cells(irow, "B").Value <> "Not Authorized"

' codes to run in the loop is here (I use SENDKEYS)

irow = irow + 1
A1 = A1 + 1
Loop
On Error GoTo 0
[/CODE
 
Tried it. It's not stopping/skipping at "Not Authorized" in B Column or blank cell in A column.
It isn't supposed to stop at "Not Authorized" in B Column as you stated
skip the row if the value contains 'Not Authorized' and just move to next row and continue with the loop.

and you didn't ask for the stop at blanks in column A in that part of the question.

The code in post number 4 by Mohadin does stop at both blanks and Not Authorized (if you change "Access Denied" to "Not Authorized")
 
Upvote 0

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
It isn't supposed to stop at "Not Authorized" in B Column as you stated


and you didn't ask for the stop at blanks in column A in that part of the question.

The code in post number 4 by Mohadin does stop at both blanks and Not Authorized (if you change "Access Denied" to "Not Authorized")
I made it a bit complicated since the other steps after this code are executed are very important and highly dependant on blanks or the text not authorized,

I found another way to execute this without a loop. Both the codes worked after making a few alterations. :)
 
Upvote 0

Forum statistics

Threads
1,215,764
Messages
6,126,750
Members
449,335
Latest member
Tanne

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top