• Status: Solved
  • Priority: Medium
  • Security: Private
  • Views: 29
  • Last Modified:

INSERT FORMULAS BASED ON CELL VALUE

I need VBA code to have formulas inserted in column R & Q based on the values in other columns.

Where column A is in { "PO","SO","E2AM","E2","ESP"}
Where column A is in { "HD", "GR"}
Where column A is in ("MWT"}  
Where column A is in {"IE", "IP", "IEF","IPF"} AND column K is in {"PR"}
Where column A is in {"IE", "IP", "IEF","IPF"} AND column H is in {"PR"}
Where column A is in {"IE", "IP", "IEF","IPF"} AND column J is in {"US"} AND column M is NOT IN {"US"}
Where column A is in {"IE", "IP", "IEF","IPF"} AND column M is in {"US"} AND column J is NOT IN {"US"}

I am attaching a data set and separate list of formulas related to the conditions.
I hope this will keep it simple!?
Can anyone help? Thank!! :)
SAMPLE-FORMULAS-DATA.xlsx
FORMULAS-FOR-RE-RATE.docx
0
Euro5
Asked:
Euro5
  • 5
  • 4
1 Solution
 
Wilder1626Commented:
Hi see that you have a lot of IF statement. It would take long to go over all of them, so i will give you something to start.
Is this what you are looking for?
If the answer is yes, you can continue to add all your If statements.

Dim c As Long, LR As Long
LR = Range("A2").End(xlDown).Row
For c = LR To 2 Step -1

'If Column A = PO
    If Cells(c, "A") = "PO" Then
        If Cells(c, "U") > 150 Then Cells(c, "Q") = "POHW"
        If Cells(c, "B") >= "Fedex Letter" Then Cells(c, "Q") = "POL"
        If Cells(c, "B") >= "Fedex Pak" Then Cells(c, "Q") = "POP"
     End If
   
'If Column A = E2
  If Cells(c, "A") = "E2" Then
       
     End If
'...........
Next

Open in new window


if result
0
 
Euro5Author Commented:
YES, thanks!
0
 
Wilder1626Commented:
Are you ok to adjust all If statement on your own based on the above macro i gave you?
0
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

 
Euro5Author Commented:
Trying to see if I can get it to work... how do I do an AND?
0
 
Wilder1626Commented:
If i take the below example

You are looking after column A where you have the value PO, if it see PO then it will look at the second statement that equals to AND. Ex: If the column U > 150 column Q will equal POHW. If the column B = Fedex Letter, then column Q = POL, etc.

 If Cells(c, "A") = "PO" Then 
        If Cells(c, "U") > 150 Then Cells(c, "Q") = "POHW"
        If Cells(c, "B") >= "Fedex Letter" Then Cells(c, "Q") = "POL"
        If Cells(c, "B") >= "Fedex Pak" Then Cells(c, "Q") = "POP"
     End If

Open in new window


Above macro could also be like below and do the same results. You would also see your AND statement:
 If Cells(c, "A") = "PO" And Cells(c, "U") > 150 Then Cells(c, "Q") = "POHW"
 If Cells(c, "A") = "PO" And Cells(c, "B") >= "Fedex Letter" Then Cells(c, "Q") = "POL"
 If Cells(c, "A") = "PO" And Cells(c, "B") >= "Fedex Pak" Then Cells(c, "Q") = "POP"
 '........... ETC.......

Open in new window


at the end, the code could be something like this:
Dim c As Long, LR As Long
LR = Range("A2").End(xlDown).Row
For c = LR To 2 Step -1

 If Cells(c, "A") = "PO" And Cells(c, "U") > 150 Then Cells(c, "Q") = "POHW"
 If Cells(c, "A") = "PO" And Cells(c, "B") >= "Fedex Letter" Then Cells(c, "Q") = "POL"
 If Cells(c, "A") = "PO" And Cells(c, "B") >= "Fedex Pak" Then Cells(c, "Q") = "POP"
    

'...........

Next

Open in new window

0
 
Euro5Author Commented:
Got it!
Working though - think this is working perfectly!
0
 
Wilder1626Commented:
This is good news. :)

let me know your final results!!!!!!!
0
 
Euro5Author Commented:
Excellent thanks so much!
0
 
Wilder1626Commented:
i'm glad i was able to help
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now