decadence
Well-known Member
- Joined
- Oct 9, 2015
- Messages
- 525
- Office Version
- 365
- 2016
- 2013
- 2010
- 2007
- Platform
- Windows
Hi, I have a column of data and every cell may or may not contain specific words, what I am trying to do is once the first instance of a word (from an array) is found then insert a column before the data column then exit completely out of the loop without looking in any other cells in the data column, Can someone help with this please. This is what I am using
Code:
Sub InsertByWord()
'
Dim RRng as range, oCell as Range, Arr as Variant, k As Integer
Arr = Array("*Apple*", "*Banana*", "*Orange*")
Set RRng = ActiveSheet.range("C:C")
For k = 0 To 2
For Each oCell In RRng
If oCell.Value Like Arr(k) Then
LR = oCell.Row
RRng.Offset(0, -1).EntireColumn.Insert
Exit For
End If
Next oCell
Next k
End Sub
Last edited: