# If True/False Condition

1. ## If True/False Condition

Hello Experts,

I am looking to implement a true/false flag in my if then statement. I tried looking on google, all I can find is IF(condition,value if true,value if false), my task is a bit more complicated.

I guess I need to set the default condition at the start, something like Default=True, and if the condition is true, it stays in the loop and perform the required tasks, if the condition is false then it jumps out of a loop and do another task.
It should look something like this

``Please Login or Register  to view this content.``

Hallet

2. ## Re: If True/False Condition

Perhaps something like
``Please Login or Register  to view this content.``

3. ## Re: If True/False Condition

That's what I did orignally, with just If...else...statements
but sicne I have to compare row by row and more than a few loops, it actually doesn't work with the traditional if..elseif ...else.
I am just looking for the macro for how to write if the above statement is True, and when the statement is false.
Thanks!

4. ## Re: If True/False Condition

Hi Hallet,

Perhaps uploading a workbook without sensitive or personal data would be best. To my understanding of
I am just looking for the macro for how to write if the above statement is True, and when the statement is false.
is exactly what I gave you so I am obviously missing the point of your requirements. In your workbook you should provide a before and after scenario of what should be happening with your data. If you do that, I'm sure your requirements will be met very quickly.

5. ## Re: If True/False Condition

Hallet,

You probably need to be a little more specific.
Where are you looping?
What is x & y?
What is a & b?
And if possible, try to put together a sample workbook which illustrates your problem and upload it.

6. ## Re: If True/False Condition

Thank you for replying guys, I am working on a sample workbook as we speak, trying to trim as much as possible becuase it's a lot of information and variables, but in the same time I want to make it clear to you.

7. ## Re: If True/False Condition

Here I have provided a modified workbook

Workbook1.xls

Sorry it took so long, as I havent got into a habbit of commenting while coding yet
I have left some comments at the start and the end explaining what I'm trying to achieve and some of the problems I'm having (too lazy to wirte the dims and ignored some other details =S)
See if you can give it a crack
Sorry if some of my codes dont make sense as I am new to VBA and programming in general

Thank you so much for your time

Hallet

8. ## Re: If True/False Condition

(1) There is no data in your worksheets, so it is hard to understand what you are attempting here.
(2) The code in your module appears to be incomplete, thus there is no way for anyone to step through the code and see what it does.
(3) Frankly, looking at your code, it is clear that you are new to programming, and so it is going to be almost impossible for anyone to help you with what you have posted so far.
(4) You should learn to code without using "Activate" as you are using it.

I would suggest that you approach things differently. If your data contains private information, then you don't want to upload such data; but you should work on creating a realistic representation of your data. And instead of starting with your end result, you should try to break your project down into steps.

For example:

(1) if you need to compare data in two different workbooks, then the first step is you should learn is how to use one workbook to open another workbook. This also means you need to have two workbooks of sample data.

(2) if you need to find data in one worksheet in another worksheet, you need learn how to use Find, or if not find, you need to learn how to loop through a column of data. You code seems to indicate that you don't know how to do either.

At each step, your code should be totally functional and working. Then if you have a problem which you cannot figure out, you can upload a program which is almost working and ask where you're going wrong.

Also, it is very important to learn modular programming. Instead of having one huge process, you should learn to break it down in separate steps, allowing sub-routines and functions to do the major work. As a rule of thumb, any time you have a sub-routine or function which is over a page long (including comments), you should probably chop it up into parts.

9. ## Re: If True/False Condition

Hi StevenM,

Thanks alot for replying. And thank you for your critiques, I really appreciate you trying to help.

I apologize for shortening and cutting critical information that's needed to run the code, and I apologize at my zero experience at coding which made it extremely hard for you to understand.

I only included part of the macro for building the cross reference files, and didn't upload any of the workbooks containing the actual data being compared, I apologize for that as well.

As of right now I have a copy with enough information for it to run without an error message popping up. But like I mentioned in the workbook, instead of looping through that column of data when it finds a mismatch in the first line, it jumps directly to TASK 2 - printing to manual_xref file. Then the terminates the module.

So i guess this is one part of the problem I should solve first.

If you think I am beyond help right now it's cool, I will keep learning in the mean time.
Otherwise I wouldn't mind a few pointers

Such as:

Can you give me an example of the "Find" function for my case. Instead of looping thought each row, I can try finding the range, and use the find function.

You mentioned I don't know how to loop through a column of data
I have learned that looping through a column not knowing the parameters, and with if statements, to use
``Please Login or Register  to view this content.``
That's how I've always did it, and it's been working out for me so far, but if you have any inputs on that, please let me know

Thank you!

10. ## Re: If True/False Condition

The following is the basic structure of looping through rows of data in a worksheet.
The following works with the Active Sheet.

``Please Login or Register  to view this content.``
But often one needs to work on some other worksheet.
The following is basically the same code as above, except it is used with a particular worksheet.
Note the use of the dot operator.

``Please Login or Register  to view this content.``
The next piece of code illustrates how to use Find.

``Please Login or Register  to view this content.``
If you only need to find one item in a range, then you wont need:

``Please Login or Register  to view this content.``
The above is for finding an item many times in a range.

Often I just copy and paste the following into my code:

``Please Login or Register  to view this content.``
Then I make modifications to the above depending on what I'm doing.

The line:
``Please Login or Register  to view this content.``
Is a double negative. It mean: If item was found!

If you want to know if it wasn't found:
``Please Login or Register  to view this content.``
The above line means: If item wasn't found!

If you need to know the row of the item found, use: rgCell.Row

11. ## Re: If True/False Condition

Thank you so much for showing me the basic structures of Loop and Find.

They were very detailed, and with the comments, very clear.
And it was very nice of you to add specific cases.
I think I learned more from that post than what I have learned myself in weeks.

I will try to implement what you showed me to my codes.

Thank you again!