PDA

View Full Version : [SOLVED:] Conditional expression



omidvakili
04-16-2020, 02:47 AM
We have a table like the one below:
26337


We want to write a code that compares all the numbers in a row as follows:
For example, check B3 and C3, if B3 and C3 are unequal to zero
then Enter A (the name of column=B2) to first blank cell in column G
and Enter B (the name of 2nd column=C2) to first blank cell in column H
else do nothing

This comparison continues for all active row in B and C column
check B4 and C4, if B4 and C4 are unequal to zero
then Enter A (the name of column=B2) to first blank cell in column G
and Enter B (the name of 2nd column=C2) to first blank cell in column H
else do nothing
and so on.
26338


After that We must also compare all the rows of columns A and C, A and D, B and C, B and D, C and D. The final result will be as shown below:
26336

p45cal
04-16-2020, 04:03 AM
I'm not sure how to interpret this:

if B3 and C3 are unequal to zero
This will affect the key line in the code:

If rngBody.Cells(rw, colm1) <> 0 And rngBody.Cells(rw, colm1) <> 0 Thenwhich may need to be adjusted.
Button in the attached runs the code.
See comments in the code.
26339

omidvakili
04-17-2020, 01:33 AM
Your coding is absolutely right, the only mistake is here:

If rngBody.Cells(rw, colm1) <> 0 And rngBody.Cells(rw, colm1) <> 0 Then
The colm2 must be entered
You did me a favor, Thanks a lot.

p45cal
04-17-2020, 02:43 AM
Well spotted!