TotalNoob122
New Member
- Joined
- Feb 23, 2022
- Messages
- 6
- Office Version
- 2019
Hello everyone,
I'm having some issues making a macro that would save me a lot of time and I need your help...
I was trying to:
It looks simple but I've been trying the Find command and has two limitations:
EXAMPLE:
I HAVE THIS:
AND I WOULD LIKE TO ADD THIS:
At the moment all I got is this :
I would really appreciate your help guys,
Thanks
I'm having some issues making a macro that would save me a lot of time and I need your help...
I was trying to:
- look for a string of text in a cell.
- Add 4 rows with content under said cell.
It looks simple but I've been trying the Find command and has two limitations:
- You have to start from finish to start, if not the position of the others cells change.
- You have to detect when you reach the first found cell or the loop would never end.
EXAMPLE:
I HAVE THIS:
AND I WOULD LIKE TO ADD THIS:
At the moment all I got is this :
Sub FindNext_Example()
Dim FindValue As String
FindValue = "CCC"
Dim Rng As Range
Set Rng = Range("A2:A111")
Dim FindRng As Range
Set FindRng = Rng.Find(What:=FindValue, LookIn:= _
xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:= _
xlNext, MatchCase:=False, SearchFormat:=False)
Dim FirstCell As String
FirstCell = FindRng.Address
Do
Rng.Select
Application.Goto FindRng
ActiveCell.Offset(1, 0).EntireRow.Insert Shift:=xlShiftDown
ActiveCell.Offset(1).EntireRow.Insert Shift:=xlShiftDown
ActiveCell.Offset(1).EntireRow.Insert Shift:=xlShiftDown
ActiveCell.Offset(1).EntireRow.Insert Shift:=xlShiftDown
¡
ActiveCell.Offset(1, 0).Range("A1").Select
ActiveCell.FormulaR1C1 = "POTATOES"
ActiveCell.Font.Color = RGB(0, 0, 0)
ActiveCell.Offset(1, 0).Range("A1").Select
ActiveCell.FormulaR1C1 = "LEMONADE"
ActiveCell.Font.Color = RGB(0, 0, 0)
ActiveCell.Offset(1, 0).Range("A1").Select
ActiveCell.FormulaR1C1 = "ORANGES."
ActiveCell.Font.Color = RGB(0, 0, 0)
ActiveCell.Offset(1, 0).Range("A1").Select
ActiveCell.FormulaR1C1 = "SPINACH"
ActiveCell.Font.Color = RGB(0, 0, 0)
Set FindRng = Rng.FindNext(FindRng)
Loop While FirstCell <> FindRng.Address
MsgBox "Search is over"
End Sub
I would really appreciate your help guys,
Thanks