Type mismatch when trying to convert to negative number

  • Thread starter Thread starter Fred Smith
  • Start date Start date
F

Fred Smith

I have a cell with the following data:

144.049S

The S means the number should be subtracted, so I want to turn it into a
negative value. My code is:

If Right(Cell.Offset(0, 8), 1) = "S" Then Cell.Offset(0, 8) = _
0 - Left(Cell.Offset(0, 8), Len(Cell.Offset(0, 8) - 1))

But I keep getting a type mismatch.

What am I doing wrong?
 
I think you put the bracket in the wront place for your Len function.
It should be

Len(Cell.offset(0,8)) - 1
instead of
Len(Cell.Offset(0, 8) - 1)
 
I think you put the bracket in the wrong place for your Len function.
It should be

Len(Cell.offset(0,8)) - 1
instead of
Len(Cell.Offset(0, 8) - 1)

Chris

Fred Smith ÀÛ¼º:
 
It looks like a misplaced ).

If Right(Cell.Offset(0, 8), 1) = "S" Then Cell.Offset(0, 8) = _
0 - Left(Cell.Offset(0, 8), Len(Cell.Offset(0, 8)) - 1)

Just to make it a little easier to read:

With Cell.Offset(0, 8)
If Right(.Value, 1) = "S" Then .Value = _
0 - Left(.Value, Len(.Value) - 1)
End With

And since I like block-If's better:

With Cell.Offset(0, 8)
If Right(.Value, 1) = "S" Then
.Value = 0 - Left(.Value, Len(.Value) - 1)
End If
End With
 
Thanks so much.

You'd think after 35 years of programming, I'd double check the parentheses, but
senility must be setting in.

Thanks for your help.

--
Regards,
Fred


I think you put the bracket in the wrong place for your Len function.
It should be

Len(Cell.offset(0,8)) - 1
instead of
Len(Cell.Offset(0, 8) - 1)

Chris

Fred Smith ÀÛ¼º:
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top