Link to home
Start Free TrialLog in
Avatar of Jase Alexander
Jase AlexanderFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Formula to check previous row results before displaying result

HI Experts

I hope you can help

I have a sheet that is completed by various personnel to detail packing requirements for shipments including weights, dimensions and stock information.

Basically, I would like to know if there is  a way in which a formula can look at the carton number in column A and if it is the same as the next line entry, then the carton dimensions are not repeated until the carton number changes.

Ive tried this formula:-

=IF(A3<>A2,g2,IF(A3<>SUM(A2+1),G2,""))

But it gives me the same result ??

I have attached an example, if you could help I would be very grateful

J
Sheet_Example.xlsx
Avatar of Rgonzo1971
Rgonzo1971

HI,

How do you get

24x24x25
is it a formula?

Regards
Avatar of Jase Alexander

ASKER

HI RG

Apologies

No this is just typed in its the height, width and depth of a packaging cardboard box that we send goods in.

What I need is for the cell below the first entry to look to see if the carton number is the same in column A and if it is, then return a blank. If it isn't (ie Carton 2) then it will allow the new carton dimensions to be visible.

This formula will be entered AFTER all the details are in unless there is a macro that can be run so that after the first entry and subsequent entry in row 3, it will look at the carton number in A3 and if its the same as A2, blocks the cells in G3 so the user cannot duplicate the carton dimensions until the carton number changes. Is this possible?

J
if cell G3 does not have the information in the first place why create a formula?
Hi RG

Apologies

I believe the user has misled me into what is requested

What is actually requested is, for example, after entering the data in row 2, a macro looks at cell A3 and if it is the same as A2 (eg 1) then cell G2 is locked. If the user enters a number that is different from A2 (ie 2) then G2 is unlocked and is enabled for cell entry (eg carton dimensions)

Is this possible?

J
then try
Sub macro()
ActiveSheet.Unprotect
Set Rng = Range(Range("A2"), Range("A" & Rows.Count).End(xlUp))
Rng.Offset(, 6).Locked = False
For Each c In Rng
    If c.Value = c.Offset(-1).Value Then c.Offset(, 6).Locked = True
Next
ActiveSheet.Protect
End Sub

Open in new window

HI RG

This is great except when I enter the macro and then try to enter a new row of data in row 12, it comes up with the 'please unprotect sheet' alert.

Is there a way to isolate the locked cells to JUST column G as when the macro is run, the user will still need to enter data however, not in Column G if the carton numbers are duplicated as explained above ??

J
then try
Sub macro()
ActiveSheet.Unprotect
Cells.Locked = False
Set Rng = Range(Range("A2"), Range("A" & Rows.Count).End(xlUp))
For Each c In Rng
    If c.Value = c.Offset(-1).Value Then c.Offset(, 6).Locked = True
Next
ActiveSheet.Protect
End Sub

Open in new window

HI RG

Thanks for the response

So Ive entered the code and it will now let me enter data into the next row (row 12) however, if I enter 4 (carton 4) in column A12 and some data through to Column G12. If I enter data into the next row (A13) as carton 4 (duplicating the previous entry) it still allows me to enter freely into Column G (G13) instead of the macro seeing that the previous entry was also carton 4 and therefore, G13 should be blocked.

Also, when I run this macro and try typing into Column G cells from G2 to G11, the locked doesn't work ??

Any ideas ? Thank you for your help by the way I really appreciate it.

J
then you have to use in the sheet module

Private Sub Worksheet_Change(ByVal Target As Range)
Me.Unprotect
Cells.Locked = False
Set Rng = Range(Range("A2"), Range("A" & Rows.Count).End(xlUp))
For Each c In Rng
    If c.Value = c.Offset(-1).Value Then c.Offset(, 6).Locked = True
Next
Me.Protect
End Sub

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Rob Henson
Rob Henson
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Alternatively, do you have a list of Carton codes with their respective dimensions. If so, use a VLOOKUP to get the dimensions rather than entering them:

=IF(A2=A1,"",VLOOKUP(A2,DimensionTable,2,False))

Thanks
Rob
See attached with both examples on separate sheets.
Sheet_Example.xlsx
HI Rob

Your Data Validation option is perfect ! Thank you so much

One question for the purpose of limiting the input further, is it possible to remove the Retry option on the Warning Alert in a Data Validation pop-up?

J
Unfortunately, I don't know of a way of doing that. There are 3 options for what error message comes up and the other two allow the user to continue with an invalid entry.

Also, one disadvantage of Data Validation, it doesn't stop the user from just copying and pasting from another cell or using the mouse to drag fill cells. It only stops physical entries.
Thanks guys for the help

Appreciated as always !!

J ;o))