Hi All,
Been grappling with this for a while - thought I had it solved before christmas but on revisiting, does not produce the reusult i need.
I have the following working code which looks at a range (containing strings of text and mumbers with 3 letters followed by a number eg AAA1, BBB5 etc) and if the fist 3 characters of that string match any of the values in the second range (which would contain text only eg AAA, BBB), to delete that value from the first range i.e;
I need to alter this so that the code can deal with values of variable length, including spaces, i.e "HELLO THERE1", "GOOD BYE2",etc, and delete those entries if the second range contains "HELLO THERE", "GOOD BYE"
The following was suggested but on further investigation, did not provide the result i was looking for (clears contents of entire range for "M44:M75" , even though there were some values in the first range and not in the second)
It appears that if you replace the "long" number value in the left() expression with anything else, that it will not work as expected - is this the case?
Is there a solution using StrComp or InStr that could be used instead? I'm a relative newbie to vb coding and not that familiar with string manipulation so you will have to bear with me!!
Perhaps it requires a totally different approach altogether - is my use of "For, Next" in the above code o.k?
Any help greatly appreciated.
Been grappling with this for a while - thought I had it solved before christmas but on revisiting, does not produce the reusult i need.
I have the following working code which looks at a range (containing strings of text and mumbers with 3 letters followed by a number eg AAA1, BBB5 etc) and if the fist 3 characters of that string match any of the values in the second range (which would contain text only eg AAA, BBB), to delete that value from the first range i.e;
Code:
Dim cell As Range
With ActiveSheet
Dim x As Integer
For x = 116 To 147
For Each cell In .Range("M44:M75")
If Left(cell.Value, 3) = .Range("H" & x).Value Then
cell.ClearContents
cell.Interior.ColorIndex = xlNone
End If
Next cell
Next x
End With
I need to alter this so that the code can deal with values of variable length, including spaces, i.e "HELLO THERE1", "GOOD BYE2",etc, and delete those entries if the second range contains "HELLO THERE", "GOOD BYE"
The following was suggested but on further investigation, did not provide the result i was looking for (clears contents of entire range for "M44:M75" , even though there were some values in the first range and not in the second)
Code:
Dim cell As Range
With ActiveSheet
Dim x As Integer
For x = 116 To 147
For Each cell In .Range("M44:M75")
If Left(cell.Value, len(.Range("H" & x).Value)) = .Range("H" & x).Value Then
cell.ClearContents
cell.Interior.ColorIndex = xlNone
End If
Next cell
Next x
End With
It appears that if you replace the "long" number value in the left() expression with anything else, that it will not work as expected - is this the case?
Is there a solution using StrComp or InStr that could be used instead? I'm a relative newbie to vb coding and not that familiar with string manipulation so you will have to bear with me!!
Perhaps it requires a totally different approach altogether - is my use of "For, Next" in the above code o.k?
Any help greatly appreciated.