In excel I have created a standard order template that should be used to create standard read-in files. I have managed to set up the standard read-in file with VBA, but I am stuck on one of the steps that must be taken in the preparation of the data.
Sample: https://ibb.co/dh48uH
From line 8, columns A through E will always be filled. However, the number of lines differs per file. What I try to achieve through VBA is:
- All lines that have the text "A + B" in column C must be duplicated.
- Of all duplicated lines, the text "A + B" in column C should be replaced with "B".
- Of the remaining (actually original) lines with the text "A + B" in column C, it should be replaced with "A".
I, as a beginner in VBA, have succeeded in the first step (although probably clumsy in the eyes of experts) but have no idea how to proceed. The things I tried based on google/YouTube doesn't work. I really hope someone can help me with this.
Code:
Sub CreateDuplicates()
a = Worksheets("Sheet1").Cells(Rows.Count, 1).End(xlUp).Row
For i = 8 To a
If Worksheets("Sheet1").Cells(i, 3).Value = "A + B" Then
Worksheets("Sheet1").Rows(i).Copy
Worksheets("Sheet1").Activate
a = Worksheets("Sheet1").Cells(Rows.Count, 1).End(xlUp).Row
Worksheets("Sheet1").Cells(a + 1, 1).Select
ActiveSheet.Paste
Worksheets("Sheet1").Activate
End If
Next i
Application.CutCopyMode = False
ThisWorkbook.Worksheets("Sheet1").Cells(1, 1).Select
End Sub
Thanks in advance for your time & help!