Ordering in pallet quantities - overriding an entered value in the same cell

Phantom645

New Member
Joined
May 25, 2020
Messages
4
Office Version
  1. 365
Platform
  1. Windows
Hi,

I have staff that place purchase orders with our parent company. I would like them to order by specific pallet quantity - lots of 105 cartons, 99 cartons...etc.

So if user enters the number of cartons they would like to order (say 100) into cell B1, but this particular product comes in pallets of 105, I need the worksheet to automatically roundup the entered value to 105 and override the original entered value in the same cell. Conversely, if the number entered is 116, I need the worksheet to round down to 105.

Example:
User enters "100" in cell B1. System rounds value to nearest 105 and overrides initial entered value. Thus cell B1 now displays 105.
User enters "540" in cell B1. System rounds value to nearest 105 and overrides initial entered value. Thus cell B1 now displays 525.

I need to apply to 13 products, thus 13 cells.

Thanks Gurus! :)

Regards,

Paul
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
You could use data validation to force the user to enter a correct factor.

=MOD(B2,VLOOKUP(A2,List,2,0))=0

Where B2 is the cell with the quantity to validate. A2 is the name of the product to validate. List refers to a 2 column table with product names in the left column and correct buying quantities in the right column.
 
Upvote 0
Thanks Jason, that could definitely work but I would prefer the automatic override function. :)
 
Upvote 0
Maybe this can help you

Nuevo Hoja de cálculo de Microsoft Excel.xlsm
AB
1Orders
2105
30
40
5105
6205
7
8
9
10
Sheet1


VBA Code:
Sub Worksheet_Change(ByVal Target As Range)

Dim CELL As Range

For Each CELL In Range("B2:B14")

If (CELL.Value > 0) And (CELL.Value < 105) Then
    CELL.Value = 105
   
ElseIf (CELL.Value > 105) And (CELL.Value < 205) Then
    CELL.Value = 205
      
End If

Next CELL
End Sub

This code checks for the values in B2:B14, if the number is >0 and <105 then puts 105, same for 205 ... you can make more scenarios.

EDIT: you have to paste the code into the desired worksheet not inside a module.
 
Upvote 0
Simplifying the vba approach, this will round a number entered into column B based on a description in column A being compared to a list in G2:H100.
I've tested it in the table below using a quantity of 500 for each item, the item not found in the list is unchanged.
Book1
ABFGH
1ItemPack
2Bananas492Apples99
3Strawberries500Oranges105
4Apples495Bananas123
5Oranges525
Sheet2
VBA Code:
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
Dim c As Range
Application.EnableEvents = False
If Not Intersect(Target, Range("B:B")) Is Nothing Then
    For Each c In Intersect(Target, Range("B:B"))
        If IsNumeric(c.Value) Then
            c.Value = Evaluate("=IFERROR(MROUND(" & c.Value & ",VLOOKUP(""" & c.Offset(, -1).Value & """,$G$2:$H$100,2,0))," & c.Value & ")")
        End If
    Next
End If
Application.EnableEvents = True
End Sub
 
Upvote 0
How about
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
   If Target.CountLarge > 1 Then Exit Sub
   If Not Intersect(Target, Range("B1:B13")) Is Nothing Then
      Application.EnableEvents = False
      Target.Value = Application.MRound(Target.Value, 105)
      Application.EnableEvents = True
   End If
End Sub
 
Upvote 0
Simplifying the vba approach, this will round a number entered into column B based on a description in column A being compared to a list in G2:H100.
I've tested it in the table below using a quantity of 500 for each item, the item not found in the list is unchanged.
Book1
ABFGH
1ItemPack
2Bananas492Apples99
3Strawberries500Oranges105
4Apples495Bananas123
5Oranges525
Sheet2
VBA Code:
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
Dim c As Range
Application.EnableEvents = False
If Not Intersect(Target, Range("B:B")) Is Nothing Then
    For Each c In Intersect(Target, Range("B:B"))
        If IsNumeric(c.Value) Then
            c.Value = Evaluate("=IFERROR(MROUND(" & c.Value & ",VLOOKUP(""" & c.Offset(, -1).Value & """,$G$2:$H$100,2,0))," & c.Value & ")")
        End If
    Next
End If
Application.EnableEvents = True
End Sub


This worked perfectly thank you! :)
 
Upvote 0
Simplifying the vba approach, this will round a number entered into column B based on a description in column A being compared to a list in G2:H100.
I've tested it in the table below using a quantity of 500 for each item, the item not found in the list is unchanged.
Book1
ABFGH
1ItemPack
2Bananas492Apples99
3Strawberries500Oranges105
4Apples495Bananas123
5Oranges525
Sheet2
VBA Code:
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
Dim c As Range
Application.EnableEvents = False
If Not Intersect(Target, Range("B:B")) Is Nothing Then
    For Each c In Intersect(Target, Range("B:B"))
        If IsNumeric(c.Value) Then
            c.Value = Evaluate("=IFERROR(MROUND(" & c.Value & ",VLOOKUP(""" & c.Offset(, -1).Value & """,$G$2:$H$100,2,0))," & c.Value & ")")
        End If
    Next
End If
Application.EnableEvents = True
End Sub

Jason, thanks again for the help so far. If I want to extend this code to a full row what changes do I need to make to the code? Looking at your code it uses offset to reference.

1590541633344.png



So in the above example, Cell A7 is the product code, Row 7 is where my staff enter the quantities for each week's order of that product.

The reference table with the data for the vlookup is 'container calc'!$A$61:$B$73

I assume that I have to repeat the code for each row?

Thanks again! :)
 
Upvote 0
No repetition needed, I've removed the column restriction from the code and replaced the offset with a reference to column A.
VBA Code:
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
Dim c As Range
If Target.Row < 7 Then Exit Sub
Application.EnableEvents = False
    For Each c In Target
        If IsNumeric(c.Value) Then
            c.Value = Evaluate("=IFERROR(MROUND(" & c.Value & ",VLOOKUP(""" & Cells(1, c.Row).Value & """,'container calc'!$A$61:$B$73 ,2,0))," & c.Value & ")")
        End If
    Next
Application.EnableEvents = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,062
Messages
6,122,923
Members
449,094
Latest member
teemeren

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