Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,670
Default How to code macro with if condition?

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


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default How to code macro with if condition?

Sub eric001()
v = Sheets("Temp").Range("B15").Value
Set myCell = Range("A1")
If InStr(1, v, "M") Then
v = Replace(v, "M", "")
Else
If InStr(1, v, "B") Then
v = Replace(v, "B", "") * 1000
End If
End If
myCell.Offset(0, 3).Value = v
End Sub

--
Gary''s Student - gsnu200773
  #3   Report Post  
Posted to microsoft.public.excel.programming
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


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
code to check condition for each row Horatio J. Bilge, Jr. Excel Discussion (Misc queries) 3 February 10th 09 08:07 PM
Condition Formatting in code. How? Corey Excel Programming 1 August 11th 06 03:18 PM
Condition Formatting in code. How? raypayette[_45_] Excel Programming 1 August 11th 06 02:55 PM
Condition Formatting in code. How? Barb Reinhardt Excel Programming 0 August 11th 06 02:28 PM
Condition added to Sort Code Todd Huttenstine[_3_] Excel Programming 1 January 2nd 04 09:35 AM


All times are GMT +1. The time now is 02:38 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"