Lil Stinker
Board Regular
- Joined
- Feb 16, 2022
- Messages
- 151
- Office Version
- 2019
- Platform
- Windows
Hey folks,
I'm looking for a code revision to fix two issues I have with the current form and how it transfers data back and forth between two worksheets. The setup is a bit complicated.
Setup:
On Sheet1 ("RA Receipt"), serial numbers are scanned into three different ranges depending on the type of equipment: Main, Secondary and Misc.
Sheet2 ("Serial Log") is where the numbers are backed up to in the same order.
Here is the code used to transfer the data row by row. All of the variables are Dimmed As Long. (This is just the relevant segment of a much larger macro that transfers different data sets to other worksheets from the same form on the RA Receipt).
Issues:
1. Because this copies data row by row, it only references B39 to establish the last item row. The problem is, if I only enter numbers into the Secondary range or the Misc range, it doesn't transfer that data over because column B is empty. How do I revise the code to recognize not just Col B and the last item row, but Col P and the last row as well as Col R and the last row?
2. I would also like to know how I can clear the entries on the Serial Log if they are deleted on the RA Receipt sheet. Currently, it only works to overwrite the data on the Serial Log. It assigns the corresponding row # to both sheets so the data matches however, if I delete any numbers from the last row on the RA Receipt and refresh the log, the Serial Log still has those numbers from the last row stored. I came up with a way to clear the entire row of the Serial Log but that is problematic because if the numbers stored in the Secondary or Misc ranges exceed the numbers stored in the Main range, clearing the entire row obviously wipes everything out regardless of the range it is in.
I feel like a cell by cell approach is a better way to go but I didn't author this code and I don't know enough about VBA to change it appropriately. I'd appreciate any help you can offer.
I'm looking for a code revision to fix two issues I have with the current form and how it transfers data back and forth between two worksheets. The setup is a bit complicated.
Setup:
On Sheet1 ("RA Receipt"), serial numbers are scanned into three different ranges depending on the type of equipment: Main, Secondary and Misc.
2-24 mrexcelTEST.xlsm | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | |||
23 | SERIAL NUMBERS | Main | Secondary | Misc | db_row | |||||||||||||||||||
24 | 202 | 850 | 1000 | 1001 | 1200 | 1250 | 1300 | 1500 | 1600 | 1700 | 1800 | 1900 | 2000 | 2100 | 123 | 444 | 24 | |||||||
25 | 2200 | 2300 | 2330 | 2400 | 2500 | 2600 | 2700 | 2800 | 2900 | 3040 | 3200 | 3300 | 3400 | 3444 | 451 | 500 | 25 | |||||||
26 | 3500 | 3505 | 3600 | 3700 | 3800 | 3900 | 4000 | 4100 | 4200 | 4300 | 4400 | 4500 | 4600 | 4650 | 500 | 508 | 26 | |||||||
27 | 4700 | 4800 | 4900 | 5000 | 5002 | 5003 | 5005 | 5400 | 5500 | 5600 | 6546 | 6549 | 7004 | 8004 | 650 | 784 | 27 | |||||||
28 | 9640 | 960 | 28 | |||||||||||||||||||||
29 | ||||||||||||||||||||||||
30 | ||||||||||||||||||||||||
31 | ||||||||||||||||||||||||
32 | ||||||||||||||||||||||||
33 | ||||||||||||||||||||||||
34 | ||||||||||||||||||||||||
35 | ||||||||||||||||||||||||
36 | ||||||||||||||||||||||||
37 | ||||||||||||||||||||||||
38 | 15001 | 8500 | 1542 | 150 | 250 | |||||||||||||||||||
RA Receipt |
Sheet2 ("Serial Log") is where the numbers are backed up to in the same order.
2-24 mrexcelTEST.xlsm | |||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | |||
2 | WR | RA No. | Page No. | sr1 | sr2 | sr3 | sr4 | sr5 | sr6 | sr7 | sr8 | sr9 | sr10 | sr11 | sr12 | sr13 | sr14 | sxb1 | sxb2 | pws1 | pws2 | RArow | Row | ||
24 | WR | 4 | 1 | 202 | 850 | 1000 | 1001 | 1200 | 1250 | 1300 | 1500 | 1600 | 1700 | 1800 | 1900 | 2000 | 2100 | 123 | 444 | 24 | 24 | ||||
25 | WR | 4 | 1 | 2200 | 2300 | 2330 | 2400 | 2500 | 2600 | 2700 | 2800 | 2900 | 3040 | 3200 | 3300 | 3400 | 3444 | 451 | 500 | 25 | 25 | ||||
26 | WR | 4 | 1 | 3500 | 3505 | 3600 | 3700 | 3800 | 3900 | 4000 | 4100 | 4200 | 4300 | 4400 | 4500 | 4600 | 4650 | 500 | 508 | 26 | 26 | ||||
27 | WR | 4 | 1 | 4700 | 4800 | 4900 | 5000 | 5002 | 5003 | 5005 | 5400 | 5500 | 5600 | 6546 | 6549 | 7004 | 8004 | 650 | 784 | 27 | 27 | ||||
28 | WR | 4 | 1 | 9640 | 960 | 28 | 28 | ||||||||||||||||||
Serial Log |
Cell Formulas | ||
---|---|---|
Range | Formula | |
W24:W28 | W24 | =ROW() |
Here is the code used to transfer the data row by row. All of the variables are Dimmed As Long. (This is just the relevant segment of a much larger macro that transfers different data sets to other worksheets from the same form on the RA Receipt).
VBA Code:
'''add / update ra serials
lastITEMROW = .Range("B39").End(xlUp).Row 'last serial row
If lastITEMROW < 24 Then GoTo NoSerials
For itemROW = 24 To lastITEMROW
If .Range("V" & itemROW).Value = Empty Then 'new ra
raITEMROW = RAseriallog.Range("A1048576").End(xlUp).Row + 1 'first avail row
RAseriallog.Range("A" & raITEMROW).Value = .Range("P4").Value 'ra prefix
RAseriallog.Range("B" & raITEMROW).Value = .Range("AD6").Value 'add ra#
RAseriallog.Range("C" & raITEMROW).Value = .Range("AB9").Value 'add page #
RAseriallog.Range("V" & raITEMROW).Value = itemROW 'ra item row
RAseriallog.Range("W" & raITEMROW).Value = "=Row()" 'add db_row
.Range("V" & itemROW).Value = raITEMROW 'add db_row to ra
Else 'existing ra item
raITEMROW = .Range("V" & itemROW).Value 'existing item row
End If
RAseriallog.Range("D" & raITEMROW & ":U" & raITEMROW).Value = Range("B" & itemROW & ":S" & itemROW).Value 'backup serials
Next itemROW
NoSerials:
Issues:
1. Because this copies data row by row, it only references B39 to establish the last item row. The problem is, if I only enter numbers into the Secondary range or the Misc range, it doesn't transfer that data over because column B is empty. How do I revise the code to recognize not just Col B and the last item row, but Col P and the last row as well as Col R and the last row?
2. I would also like to know how I can clear the entries on the Serial Log if they are deleted on the RA Receipt sheet. Currently, it only works to overwrite the data on the Serial Log. It assigns the corresponding row # to both sheets so the data matches however, if I delete any numbers from the last row on the RA Receipt and refresh the log, the Serial Log still has those numbers from the last row stored. I came up with a way to clear the entire row of the Serial Log but that is problematic because if the numbers stored in the Secondary or Misc ranges exceed the numbers stored in the Main range, clearing the entire row obviously wipes everything out regardless of the range it is in.
I feel like a cell by cell approach is a better way to go but I didn't author this code and I don't know enough about VBA to change it appropriately. I'd appreciate any help you can offer.