Baijano23
New Member
- Joined
- Aug 15, 2024
- Messages
- 1
- Office Version
- Prefer Not To Say
- Platform
- Windows
Hello all!
I’m fairly new to using VBA but trying to get as much out of it as possible! I’m working on a code that will search for a specific phrase (ADD-CAS) in a cell and add a row above it. Once that is done, I then want to an add “Loaded” to a cell 6 cells above and 23 cells to the right of ADD-CAS. I have this working ok with the below code. Where I’m struggling is I also need to add “Dispensed”, “Expected”, “Reported” and “Variance” in that order, below “Loaded”. I’ve tried copying the same code but adding -5 for “Dispensed” however that just seems to overwrite the “Loaded” and then only shows “Dispensed”
What do I need to do to show all 5 of the phrases mentioned above at the same time?
The code I have so far:
Dim m As Long
Dim Lastrow2 As Long
Lastrow2 = Cells(Rows.Count, "D").End(xlUp).Row
For m = Lastrow2 To 1 Step -1
If Cells(m, "D").Value = "ADD-CAS" Then Cells(m, "D").EntireRow.Insert xlShiftDown
Next
Application.ScreenUpdating = True
With Range("D8", Range("D" & Rows.Count).End(xlUp))
.Offset(-6, 21).Value = Evaluate("if(isnumber(search(""ADD-CAS""," & .Address & ")),""Loaded"","""")")
End With
I’ve posted via my mobile so apologies if this has formatted terribly!
I’m fairly new to using VBA but trying to get as much out of it as possible! I’m working on a code that will search for a specific phrase (ADD-CAS) in a cell and add a row above it. Once that is done, I then want to an add “Loaded” to a cell 6 cells above and 23 cells to the right of ADD-CAS. I have this working ok with the below code. Where I’m struggling is I also need to add “Dispensed”, “Expected”, “Reported” and “Variance” in that order, below “Loaded”. I’ve tried copying the same code but adding -5 for “Dispensed” however that just seems to overwrite the “Loaded” and then only shows “Dispensed”
What do I need to do to show all 5 of the phrases mentioned above at the same time?
The code I have so far:
Dim m As Long
Dim Lastrow2 As Long
Lastrow2 = Cells(Rows.Count, "D").End(xlUp).Row
For m = Lastrow2 To 1 Step -1
If Cells(m, "D").Value = "ADD-CAS" Then Cells(m, "D").EntireRow.Insert xlShiftDown
Next
Application.ScreenUpdating = True
With Range("D8", Range("D" & Rows.Count).End(xlUp))
.Offset(-6, 21).Value = Evaluate("if(isnumber(search(""ADD-CAS""," & .Address & ")),""Loaded"","""")")
End With
I’ve posted via my mobile so apologies if this has formatted terribly!