View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Mike H Mike H is offline
external usenet poster
 
Posts: 11,501
Default How to code macro with if condition?

Possibly

Sub sonic()
Set myCell = Range("D6")
myCell.Offset(0, 3).Value = Sheets("Temp").Range("B15").Value
myvalue = Sheets("Temp").Range("B15").Value
If Right(myvalue, 1) = "B" Then
Sheets("Temp").Range("B15").Value = Left(myvalue, Len(myvalue) - 1) * 1000
myCell.Offset(0, 3).Value = Sheets("Temp").Range("B15").Value
ElseIf Right(myvalue, 1) = "M" Then
Sheets("Temp").Range("B15").Value = Left(myvalue, Len(myvalue) - 1)
myCell.Offset(0, 3).Value = Sheets("Temp").Range("B15").Value
End If
End Sub

Mike

"Eric" wrote:

Does anyone have any suggestions on how to code macro with if condition?

My code:
myCell.Offset(0,3).Value = Sheets("Temp").Range("B15").Value

If Sheets("Temp").Range("B15").Value contains "B" character, then delete "B"
and time 1000 with this number, such as 254.63B will become 254630 and assign
into myCell.Offset(0,3).Value
else
If Sheets("Temp").Range("B15").Value contains "M" character, then delete
"M", such as 117.46M will become 117.46 and assign into
myCell.Offset(0,3).Value

Does anyone have any suggestions?
Thank you very much for any suggestions
Eric