Hi Guys,
I wonder if you can help please
I am not really ggod with VBA so I was wondering if anyone can help
I need to have a IF and formla in VBA for a range if cells.
PLease se sample attached
Any help would be great
Thanks
Vito
Hi Guys,
I wonder if you can help please
I am not really ggod with VBA so I was wondering if anyone can help
I need to have a IF and formla in VBA for a range if cells.
PLease se sample attached
Any help would be great
Thanks
Vito
Why VBA?
You can achieve this with a formula and conditional formatting, and it would be automatic - no clicking to validate.
Your sample data is incorrect, by the way.
In E2 copied down:
=IF(AND(B2="Acquavi",A2="Vito"),"BAD","")
Your existing CF will do the rest.
Last edited by AliGW; 03-17-2019 at 06:24 AM.
Ali
Enthusiastic self-taught user of MS Excel who's always learning!
Don't forget to say "thank you" in your thread to anyone who has offered you help.
You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.
Forum Rules (updated August 2023): please read them here.
Hey,
Thanks a million for coming back to me
The reason for it is because I need the message to appear based on the given conditions and then employee will type over the cells wich have the macro. I have tried with the conditional formatting but there is a limitation. With conditional formatting I can red color the cell but then not sure as to how make the alert text appear within the cell.
I hoep this is clear
Thanks
Vito
I've shown you. However, if you want an employee to be able to overwrite that column, you probably do need VBA. Why would they need to be able to overwrite a validation column, though?
Hi,
Might be easier to expalin by showing you a better example (see attached).
Currently in column "N" I have set the two conditions: 1 via formula and one via condtional formatting. If I could avoid this and have both set cond formats for coulmn "M" via a macro instead
Can you think of a better solution? I was hoping the conditonal formatt would this can be done but as per attached but in column "M" and then the employee could type over the vat amout
Thanks
Vito
Edit: I will have a look at your new example also.. but I rewriten your first macro
biggest problem in that macro is that you are trying to fill a value in a whole column, that does not work (as you noticed)
you need to loop thru the lines and assign bad or ok to each line
look at this code ( I stayed as close as possible to your code to help understand the differences)
Please Login or Register to view this content.
Thank you! It is great.
Hi,
Can I ask you, is it possible to make the message appear/change instantly without haveing to click on the validation button?
Thanks
Vito
Sure.. that was a bit of my plan after I saw your new example.
so that resulted in 1 code which i Put in Module1 this is to validate 1 line in the expense form.
I also choose not to use the help column and CF to color the cells. In my code the Column M cell will be made RED if there is no amount and a comment is inserted. to warn the user an amount needs filling.
To trigger this code there are 2 ways.Please Login or Register to view this content.
first is an event macro that needs to be put in the sheet module called sheet1(EXPENSE CLAIM FORM)
This event macro will trigger each time a cell in the range H12:M24 is changed (I assumed the expense form would be 12 lines long from 12 to 24 but this ofcourse can be changed to your needs)Please Login or Register to view this content.
What the event macro does is ask to excecute the line validation macro for the current line based on Target.row as row to validate (Target is comparable to Activecell and is used in eventmacros by default)
The other way to trigger is by a second piece of code in Module1. The name of that form speaks for itself it will test the whole expense form again for VAT lines. This might be usefull to have for the accounting staff to (Double) check submitted forms.
This code is nothing more than a simple loop that will call the line validations where r is the rownumber to validate. again the assumption here that expence form has 12 rows from 12 to 24 which you can simply adjust to actual no of last possible rowPlease Login or Register to view this content.
I choose not to use conditional formatting because then you would basicly create 2 validations 1 thru vba and 1 in conditional formatting formula. which will hold the risk that one is changed but not the other giving inconsistent results. So I feel it is better to control the message and format of cell in 1 code.
have a look at the attachment for some testruns...
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks