PC Review


Reply
Thread Tools Rate Thread

How to code macro with if condition?

 
 
Eric
Guest
Posts: n/a
 
      16th Mar 2008
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 With Quote
 
 
 
 
Gary''s Student
Guest
Posts: n/a
 
      16th Mar 2008
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
 
Reply With Quote
 
Mike H
Guest
Posts: n/a
 
      16th Mar 2008
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 With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to code macro with condition? Eric Microsoft Excel Programming 4 23rd Apr 2010 05:04 AM
Code condition LiAD Microsoft Excel Programming 3 8th Dec 2009 10:45 AM
Run Macro when a condition is met EXCELMACROS Microsoft Excel Programming 7 6th Jan 2009 08:14 PM
Prevent macro or code from running until a condition is met Richardson Microsoft Access Form Coding 3 4th May 2004 04:40 PM
Condition Macro Faris_dxb Microsoft Access Macros 4 21st Apr 2004 12:12 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:13 AM.