Consulting

Results 1 to 4 of 4

Thread: Conditional expression

  1. #1

    Conditional expression

    We have a table like the one below:
    101.jpg


    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.
    102.jpg


    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:
    103.jpg

  2. #2
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,876
    I'm not sure how to interpret this:
    Quote Originally Posted by omidvakili View Post
    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 Then
    which may need to be adjusted.
    Button in the attached runs the code.
    See comments in the code.
    2020-04-16_115820.jpg
    Attached Files Attached Files
    Last edited by p45cal; 04-16-2020 at 04:17 AM.
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  3. #3
    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.

  4. #4
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,876
    Well spotted!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •