Entering a set number whenever a criteria is met

dpaton05

Well-known Member
Joined
Aug 14, 2018
Messages
2,352
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
I have a spreadsheet that has many quotes in it.

  • Each line is a quote and the quotes all have a request number.
  • The quotes start in row 4 and go down from there with heading/title etc above
  • Column C has the request number
  • I need a way to be able to search for all the request numbers and enter a purchase order number for that quote
  • The purchase order number is in column B
At the top of the spreadsheet, I have 2 cells, to enter the purchase order number aND one to enter the request number.
  • The cell to enter the request number is in F1 and the cell to enter the purchase order number is in H1.
How would I go about entering a request number in F1 and a purchase order number in H1 and I need the purchase order number to be copied to every quote with that request number, as I am not sure?
 
Last edited:

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Add-in XL2BB can be downloaded to allow you to post sample data and required results
Click on link above reply window and read all the instructions
 
Upvote 0
Thanks, that tool is pretty cool. Here is the capture:

Book1
ABCDEFGHIJ
1501 NPSS DecemberReq #Purchase order #
2
3DatePurchase order #Req #Child NameServiceRequesting OrganisationCaseworker NamePrice ex. GSTGSTPrice inc. GST
December


The quotes will start in row 4.
 
Upvote 0
I don't know if the idea I am suggesting is the best way to do this. There may be better ways but it was all I could think of.
 
Upvote 0
Book1
ABCDEFGH
1Req #10119Purchase order #5000
2
3DatePurchase order #Req #Child NameServiceRequesting OrganisationCaseworker NamePrice ex. GST
413/12/201910110xxxxxxxxxxxx
513/12/201910099xxxxxxxxxxxx
614/12/201910099xxxxxxxxxxxx
716/12/201910119xxxxxxxxxxxx
816/12/201910130xxxxxxxxxxxx
918/12/201910099xxxxxxxxxxxx
1020/12/201910130xxxxxxxxxxxx
1120/12/201910132xxxxxxxxxxxx
1221/12/201910119xxxxxxxxxxxx
1321/12/201910130xxxxxxxxxxxx
1421/12/201910133xxxxxxxxxxxx
November


Here is an example with data. Using the example, I want to enter 5000 in the purchase order column (B) for every row that has a request number (C) of 10119. As the purchase order number for a given request is received, it will be added into H1 and for every quote that has the request number entered in F1, the purchase order number will need to be entered in column B.

I know this would be simply done with a bit of vba. Could someone help me please?
 
Last edited:
Upvote 0
Try this
The code is trigerred when F1 already contains a value and a value is entered in H1

right click on sheet tab \ click on View Code \ paste the code into the window that opens \ back to Excel with {ALT}{F11}

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    Dim Req As Range, PO As Range, ReqRng As Range, Cel As Range
    Set Req = Range("F1")
    Set PO = Range("H1")
    Set ReqRng = Range("C4", Range("C" & Rows.Count).End(xlUp))

    If Not Intersect(Target, PO) Is Nothing Then
        Application.EnableEvents = False
        If PO > 0 And Req > 0 Then
            For Each Cel In ReqRng
                If Cel = Req Then Cel.Offset(, -1) = PO
            Next
        End If
        PO.ClearContents
        Req.ClearContents
        Application.EnableEvents = True
    End If
End Sub


I will be offline for the next 12 hours and will deal with any observations & queries after that
 
Upvote 0
Nothing happens when I add that code and try to update H1 and F1 already has a value.
 
Upvote 0
The code works - I tested it
PO Req.jpg


Are you sure you put it in the correct place?
It will only work if placed in the sheet module
 
Upvote 0
I had the code at the bottom of the module. I moved to to the top and now it works perfectly. Thank you :)
 
Upvote 0
I had the code at the bottom of the module. I moved to to the top and now it works perfectly
That is a new one! I wish I understood what you did that VBA did not approve of. :unsure:

I am glad it now works
 
Upvote 0

Forum statistics

Threads
1,215,352
Messages
6,124,449
Members
449,160
Latest member
nikijon

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top