decadence
Well-known Member
- Joined
- Oct 9, 2015
- Messages
- 525
- Office Version
- 365
- 2016
- 2013
- 2010
- 2007
- Platform
- Windows
Hi, I am having a problem with multiple if statements, If a word is found in a cell from the array then if the offset cell equals a value then replace the offset cell with a new value, However depending on what has been found from the array needs to step through a different if statement to change the rotations, can someone help with this please. Also the words are not case sensitive.
Code:
Sub ChangeRotations()
'
Dim x As range, Rng As range, Arr As Variant, i
Set Rng = Selection
Arr = Array("Apple123", "Banana143", "Carrot23-8", "Dairy-102mlc", "Eggs456")
For i = LBound(Arr) To UBound(Arr)
For Each x In Rng
If Trim(x) <> "" Then
If Trim(x) = Arr(i) Then '<--------- If Apple123 or Eggs456 is found from string within cell value
If x.Offset(, 2).Value = "0" Then x.Offset(, 2).Value = "90"
If x.Offset(, 2).Value = "90" Then x.Offset(, 2).Value = "180"
If x.Offset(, 2).Value = "180" Then x.Offset(, 2).Value = "270"
If x.Offset(, 2).Value = "270" Then x.Offset(, 2).Value = "0"
End If
If Trim(x) = Arr(i) Then '<--------- If Banana143 is found from string within cell value
If x.Offset(, 2).Value = "0" Then x.Offset(, 2).Value = "270"
If x.Offset(, 2).Value = "90" Then x.Offset(, 2).Value = "0"
If x.Offset(, 2).Value = "180" Then x.Offset(, 2).Value = "90"
If x.Offset(, 2).Value = "270" Then x.Offset(, 2).Value = "180"
End If
If Trim(x) = Arr(i) Then '<--------- If Carrot23-8 is found from string within cell value
If x.Offset(, 2).Value = "0" Then x.Offset(, 2).Value = "315"
If x.Offset(, 2).Value = "90" Then x.Offset(, 2).Value = "45"
If x.Offset(, 2).Value = "180" Then x.Offset(, 2).Value = "135"
If x.Offset(, 2).Value = "270" Then x.Offset(, 2).Value = "225"
End If
If Trim(x) = Arr(i) Then '<--------- If Dairy-102mlc is found from string within cell value
If x.Offset(, 2).Value = "0" Then x.Offset(, 2).Value = "45"
If x.Offset(, 2).Value = "90" Then x.Offset(, 2).Value = "135"
If x.Offset(, 2).Value = "180" Then x.Offset(, 2).Value = "225"
If x.Offset(, 2).Value = "270" Then x.Offset(, 2).Value = "315"
End If
End If
Next x
Next i
End Sub