I have a list of parts numbers with short descriptions and long descriptions. The list is formatted in such a way that in the first column there is a part number. In the second column there is a description code. In the third column there is a description. The description is either the name, short description, or long description based on the preceding description code.
See screenshot example: Original Dataset
As you can see, some of the parts have all three descriptions and some of them don't.
I'm trying to take the data from sheet 1 and paste the information into sheet 2 that has the consolidated and proper row structure ie. part number, name, short, long.
See screenshot example: New Dataset
Here is some code I've been working with. I feel like I'm close or at least on the right track but it definitely isn't working and currently throwing a next without for error.
Dim i As Long
For i = 1 To Rows.Count
With ActiveWorkbook
.Sheets("Parts List").Range("A1").Select
If .Sheets("Parts List").Cells(i, 1).Value = .Sheets("Product Description").Cells(i, 1) Then
If .Sheets("Product Description").Cells(i, 2).Value = "DES" Then
.Sheets("Parts List").Cells(i, 2).Value = .Sheets("Product Description").Cells(i, 2).Value
ElseIf .Sheets("Product Description").Cells(i, 2).Value = "EXT" Then
.Sheets("Parts List").Cells(i, 5).Value = .Sheets("Product Description").Cells(i, 2).Value
ElseIf .Sheets("Product Description").Cells(i, 2).Value = "MKT" Then
.Sheets("Parts List").Cells(i, 3).Value = .Sheets("Product Description").Cells(i, 2).Value
End If
Next i
End With
Any and all help would be greatly appreciated. I'm really just trying to get it to loop through this one sheet and extract things and put them on another sheet. Sounds easy enough.
I would make a few minor changes to your code, mainly to keep a counter of which row you are writing to on the destination sheet, plus quite a few cosmetic changes:
The "Next without a For" error that you were getting was due to an unmatched
If
statement (your firstIf
statement had no correspondingEnd If
) and yourWith
block started inside yourFor
loop but finished after the loop ended. That type of error is easily picked up by always / consistently indenting your code. Below is what your original code looked like once it was indented: