MissingInAction
Board Regular
- Joined
- Sep 20, 2019
- Messages
- 85
- Office Version
- 365
- Platform
- Windows
Good day everyone.
I'm looking for some help regarding a VBA script. I have an Excel database that a user must input data for a weighbridge/landfill facility. When a truck comes in, it is weighed, its data is captured and the truck can dump its cargo. When it leaves, it is weighed again and the difference is noted to know how many tons of cargo was dumped. This means the entry can only be sent to the database after the truck leaves. I have made provision for 10 entries to be used at the same time, since more than one truck can be on the facility before it leaves. Trucks also do not leave in the order they arrive. Once the truck has left and all data is filled in, the user can click a button that moves the data from the "Input" sheet to the "Data" sheet. Here is the code used:
The macro is the same for the other 9 entries, the only difference is the range that is copied and cleared. You'll notice that I copy range A4:K4 but I only clear B4:K4. This is intended. Column A contains a date that I use for pivot table purposes and is linked to an data validation where the user can select the date range and must only change when its a new month.
The user must not be able to alter the entries after this code is executed, so I hide the cells in sheet "Data" and password protect the sheet. All of this works fine.
The problem comes where Column B range B4:B13 on the "Input" sheet contains a value that must never be duplicated in the entire Column B on the "Data" sheet. I have found plenty of CountIf formulas (example COUNTIF(Data!B:B;B2)=1) that can check for duplicates, but since my data is moved to another sheet and I only have 10 fields for entering data, it does not work that well.
My knowledge of VBA coding is next to nothing. I need help to modify the code above so that when a user enters a value in Column B (range B4:B13) on the "Input" sheet, that is already used in Column B on the "Data" sheet, he must get a message stating that the value is duplicated. Alternatively if there is a data validation formula I can use that will look for duplicates in the entire B Column on the "Data" sheet, using the values entered in range B4:B13 on the "Input" sheet, that would be great as well.
I hope someone can help me with this.
Thank you in advance
I'm looking for some help regarding a VBA script. I have an Excel database that a user must input data for a weighbridge/landfill facility. When a truck comes in, it is weighed, its data is captured and the truck can dump its cargo. When it leaves, it is weighed again and the difference is noted to know how many tons of cargo was dumped. This means the entry can only be sent to the database after the truck leaves. I have made provision for 10 entries to be used at the same time, since more than one truck can be on the facility before it leaves. Trucks also do not leave in the order they arrive. Once the truck has left and all data is filled in, the user can click a button that moves the data from the "Input" sheet to the "Data" sheet. Here is the code used:
Code:
<code>Sub Received_Entry_1()
' Copy data entry and go to Data sheet
Range("A4:K4").Select
Selection.Copy
Sheets("Data").Select
Range("A2").Select
' Select last empty row
Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Select
' Paste entry
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
' Go to Input sheet and clear entry
Sheets("Input").Select
Range("B4:K4").Select
Range("K4").Activate
Selection.ClearContents
Range("B4").Select
End Sub</code>
The macro is the same for the other 9 entries, the only difference is the range that is copied and cleared. You'll notice that I copy range A4:K4 but I only clear B4:K4. This is intended. Column A contains a date that I use for pivot table purposes and is linked to an data validation where the user can select the date range and must only change when its a new month.
The user must not be able to alter the entries after this code is executed, so I hide the cells in sheet "Data" and password protect the sheet. All of this works fine.
The problem comes where Column B range B4:B13 on the "Input" sheet contains a value that must never be duplicated in the entire Column B on the "Data" sheet. I have found plenty of CountIf formulas (example COUNTIF(Data!B:B;B2)=1) that can check for duplicates, but since my data is moved to another sheet and I only have 10 fields for entering data, it does not work that well.
My knowledge of VBA coding is next to nothing. I need help to modify the code above so that when a user enters a value in Column B (range B4:B13) on the "Input" sheet, that is already used in Column B on the "Data" sheet, he must get a message stating that the value is duplicated. Alternatively if there is a data validation formula I can use that will look for duplicates in the entire B Column on the "Data" sheet, using the values entered in range B4:B13 on the "Input" sheet, that would be great as well.
I hope someone can help me with this.
Thank you in advance