so i have a worksheet that has a 4 digit item number and a 5 digit item number (separate cells). I have thousands of these items with the item numbers. I have tried to write a code that will go through the "old" numbers (the larger list) and copy them to the new list. the new list is a requested list of a couple hundred from the larger list. i want to copy the description of these items, not the item numbers
what i have tried to write is a for loop for the new list with a for loop inside of that with the old list. the inside for loop will run through the old list adn search each row until it can match up the new item number with the old item number. i then want it to paste the description into the cell next to the new list. so the inner loop will run thru all the old list and the outer loop will run through the new list
if i am not doing this efficiently then please let me know of a better way. i will attach the code below. let me know if you have any questions
Sub Populate()
Dim fourdigitnew As Double, fivedigitnew As Double, fourdigitold As Double, fivedigitold As Double
Dim ws As Worksheet
Dim primaveraruns As Long, i As Long, vdotruns As Long, n As Long
Set ws = ActiveSheet
Dim descriptionold As String, descriptionnew As String
primaveraruns = Application.InputBox("How Many P Runs? ")
vdotruns = Application.InputBox("How Many vdot Runs?")
For i = 1 To primaveraruns
fourdigitnew = ws.Cells(2 + i, 1)
fivedigitnew = ws.Cells(2 + i, 2)
descriptionnew = ws.Cells(2 + 1, 4)
For n = 1 To vdotruns
descriptionold = ws.Cells(2 + i, 9)
fourdigitold = ws.Cells(2 + i, 7)
fivedigitold = ws.Cells(2 + i, 8)
If fourdigitold = fourdigitnew And fivedigitold = fivedigitnew Then
descriptionold = descriptionnew
Else: descriptionold = ""
End If
Next n
Next i
End Sub
what i have tried to write is a for loop for the new list with a for loop inside of that with the old list. the inside for loop will run through the old list adn search each row until it can match up the new item number with the old item number. i then want it to paste the description into the cell next to the new list. so the inner loop will run thru all the old list and the outer loop will run through the new list
if i am not doing this efficiently then please let me know of a better way. i will attach the code below. let me know if you have any questions
Sub Populate()
Dim fourdigitnew As Double, fivedigitnew As Double, fourdigitold As Double, fivedigitold As Double
Dim ws As Worksheet
Dim primaveraruns As Long, i As Long, vdotruns As Long, n As Long
Set ws = ActiveSheet
Dim descriptionold As String, descriptionnew As String
primaveraruns = Application.InputBox("How Many P Runs? ")
vdotruns = Application.InputBox("How Many vdot Runs?")
For i = 1 To primaveraruns
fourdigitnew = ws.Cells(2 + i, 1)
fivedigitnew = ws.Cells(2 + i, 2)
descriptionnew = ws.Cells(2 + 1, 4)
For n = 1 To vdotruns
descriptionold = ws.Cells(2 + i, 9)
fourdigitold = ws.Cells(2 + i, 7)
fivedigitold = ws.Cells(2 + i, 8)
If fourdigitold = fourdigitnew And fivedigitold = fivedigitnew Then
descriptionold = descriptionnew
Else: descriptionold = ""
End If
Next n
Next i
End Sub