This code is tested and works, but I am needing some guidance on simplifying these loops with non-contiguous ranges. I was thinking an array
might be better, but I haven't had enough experience with Arrays
to know where to start with one. Any guidance would be greatly appreciated.
Dim r As Range
Dim v
For Each r In JHACheck.Range("M7:M32")
v = r.Value
If v <> "" Then
If Not r.HasFormula Then
r.Value = Trim(v)
End If
End If
Next r
For Each r In JHACheck.Range("M35:M41")
v = r.Value
If v <> "" Then
If Not r.HasFormula Then
r.Value = Trim(v)
End If
End If
Next r
For Each r In JHACheck.Range("R35:R41")
v = r.Value
If v <> "" Then
If Not r.HasFormula Then
r.Value = Trim(v)
End If
End If
Next r
For Each r In JHACheck["M7:M32,M35:M41R35:R41"]
It wouldn't decrease the speed but it would reduce the duplication of code. Otherwise you would need to create an array of ranges to reduce the duplication. \$\endgroup\$