Left and Len problem

danno79

New Member
Joined
Oct 28, 2009
Messages
45
Hi all - i'm wrestling with the following problem;- I have working code;-

Code:
Dim cell As Range
Dim x As Integer

With ActiveSheet
    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
But i need to modify this so that it can cope with cell.value of variable length and remove the last characer from the string something like;-

Code:
If Left(cell.Value, len(cell.value-1)) = .Range("H" & x).Value Then
But his doesn't work - any suggestions please?
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
Code:
If Left(cell.Value, len(cell.Value[COLOR=red][B])-1[/B][/COLOR]) = .Range("H" & x).Value Then

You were subtracting 1 from cell.Value and then finding the length of cell.Value-1; you should have been finding the length of cell.Value and then subtracting 1 from the length.
 
Upvote 0

Forum statistics

Threads
1,215,332
Messages
6,124,313
Members
449,152
Latest member
PressEscape

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top