While Wend Statement

jex57

Board Regular
Joined
Oct 29, 2015
Messages
62
Hi,
Can one use AND in a while wend statement:

While Sheets(DataSheetName).Cells(countCol, 1) <> "" And Sheets(DataSheetName).Cells(countCol, 3) <> "" And Sheets(DataSheetName).Cells(countCol - 1, 1) <> ""

When I use this statement, it does not read the AND statement, so even though there is data in my last column it exits the loops.
Not too sure what I am doing wrong, or if I should not be using While and AND in the same statement.

Any advice would be appreciated.
Thank you

Immediate Window results are:
?sheets(DataSheetName).Cells(countCol - 1, 1)
PartyKey
?Sheets(DataSheetName).Cells(countCol, 1)


False
? Sheets(DataSheetName).Cells(countCol, 3)
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
Your variable name (countCol) suggests to me that you have the arguments for the Cells object reversed. The first argument should be the row number and the second argument should be either the column number or the quoted column letter designation.
 
Last edited:
Upvote 0
Thanks - variable names are correct - just the way I coded it because of number of counts that I need (column referring to what I am counting and not ROW Column in excel

Have tried brackets and trying to avoid multiple While statements, but does not read the AND clause at all
 
Upvote 0
Works perfectly well for me. I set up a dummy worksheet to check:

Code:
DataSheetName = "sheet1"
countCol = 2

While Sheets(DataSheetName).Cells(countCol, 1) <> "" And Sheets(DataSheetName).Cells(countCol, 3) <> "" And Sheets(DataSheetName).Cells(countCol - 1, 1) <> ""
    MsgBox countCol
    countCol = countCol + 1
Wend

It will run through column A and column C until it finds an empty cell in either.
 
Upvote 0

Forum statistics

Threads
1,224,817
Messages
6,181,144
Members
453,021
Latest member
Justyna P

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