Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / March 2008

Tip: Looking for answers? Try searching our database.

How to code macro with if condition?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Eric - 16 Mar 2008 16:25 GMT
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
Gary''s Student - 16 Mar 2008 16:40 GMT
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

Signature

Gary''s Student - gsnu200773

Mike H - 16 Mar 2008 16:54 GMT
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

> Does anyone have any suggestions on how to code macro with if condition?
>
[quoted text clipped - 12 lines]
> Thank you very much for any suggestions
> Eric
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.