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 use substitute function in macro?

Does anyone have any suggestions on using substitute function in macro?
I would like to remove any "B" character within the return value from
Sheets("Temp").Range("$J$15").Value.

------------------------------
Macro coding
myCell.Offset(0, 5).Value = Sheets("Temp").Range("$J$15").Value
------------------------------

For example
if the return value for Sheets("Temp").Range("$J$15").Value is 25.8B, then I
would like to substitute "B" with "", which should return 25.8 into
myCell.Offset(0, 5).Value.
Does anyone have any suggestions?
Thanks in advance for any suggestions
Eric
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,118
Default How to use substitute function in macro?

How about just using the VBA version:

Try this:

myCell.Offset(0, 5).Value = _
Replace( _
Expression:=Sheets("Temp").Range("$J$15").Value, _
Find:="B", _
Replace:="", _
Compa=vbTextCompare)

Is that something you can work with?
Post back if you have more questions.
--------------------------

Regards,

Ron
Microsoft MVP (Excel)
(XL2003, Win XP)

"Eric" wrote in message
...
Does anyone have any suggestions on using substitute function in macro?
I would like to remove any "B" character within the return value from
Sheets("Temp").Range("$J$15").Value.

------------------------------
Macro coding
myCell.Offset(0, 5).Value = Sheets("Temp").Range("$J$15").Value
------------------------------

For example
if the return value for Sheets("Temp").Range("$J$15").Value is 25.8B, then
I
would like to substitute "B" with "", which should return 25.8 into
myCell.Offset(0, 5).Value.
Does anyone have any suggestions?
Thanks in advance for any suggestions
Eric



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default How to use substitute function in macro?

Don't use the SUBSTITUTE function... since you are in a macro and your
substitution is pretty basic, use the VBA Replace function instead (it will
be faster)..

myCell.Offset(0, 5).Value = Replace(Sheets("Temp").Range("$J$15").Value,
"B", "")

Rick


"Eric" wrote in message
...
Does anyone have any suggestions on using substitute function in macro?
I would like to remove any "B" character within the return value from
Sheets("Temp").Range("$J$15").Value.

------------------------------
Macro coding
myCell.Offset(0, 5).Value = Sheets("Temp").Range("$J$15").Value
------------------------------

For example
if the return value for Sheets("Temp").Range("$J$15").Value is 25.8B, then
I
would like to substitute "B" with "", which should return 25.8 into
myCell.Offset(0, 5).Value.
Does anyone have any suggestions?
Thanks in advance for any suggestions
Eric


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,670
Default How to use substitute function in macro?

Referring to the post index function
Does anyone have any suggestions on how to use index function in coding macro?

myCell.Offset(0, 2).Value =
Index(B:B [under Temp worksheet],match("Industry",A:A [under Temp
worksheet],0))

Does anyone have any suggestions?
Thanks in advance for any suggestions
Eric


"Ron Coderre" wrote:

How about just using the VBA version:

Try this:

myCell.Offset(0, 5).Value = _
Replace( _
Expression:=Sheets("Temp").Range("$J$15").Value, _
Find:="B", _
Replace:="", _
Compa=vbTextCompare)

Is that something you can work with?
Post back if you have more questions.
--------------------------

Regards,

Ron
Microsoft MVP (Excel)
(XL2003, Win XP)

"Eric" wrote in message
...
Does anyone have any suggestions on using substitute function in macro?
I would like to remove any "B" character within the return value from
Sheets("Temp").Range("$J$15").Value.

------------------------------
Macro coding
myCell.Offset(0, 5).Value = Sheets("Temp").Range("$J$15").Value
------------------------------

For example
if the return value for Sheets("Temp").Range("$J$15").Value is 25.8B, then
I
would like to substitute "B" with "", which should return 25.8 into
myCell.Offset(0, 5).Value.
Does anyone have any suggestions?
Thanks in advance for any suggestions
Eric




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,118
Default How to use substitute function in macro?

Here are several alternatives:

myCell.Offset(0, 2).Value = _
WorksheetFunction.Index(Sheets("Temp").Range("B:B" ), _
WorksheetFunction _
.Match("Industry", Sheets("Temp").Range("A:A"), 0)).Value

or...

myCell.Offset(0, 2).Value = _
Sheets("Temp").Range("B:B") _
.Cells(WorksheetFunction _
.Match("Industry", Sheets("Temp").Range("A:A"), 0))

or...

myCell.Offset(0, 2).Value = _
Sheets("Temp").Cells(WorksheetFunction _
.Match("Industry", Sheets("Temp").Range("A:A"), 0), 2)

or...with no worksheet function calls:

myCell.Offset(0, 2).Value = _
Sheets("Temp").Range("A:A") _
.Find(What:="Industry", LookAt:=xlWhole, MatchCase:=False) _
.Offset(ColumnOffset:=1).Value


Note, though, you'll probably need to trap the error
caused if "Industry" is not found.

Something like this:

Dim rFindResult As Range
Set rFindResult = Sheets("Temp").Range("A:A") _
.Find(What:="Industry", LookAt:=xlWhole, MatchCase:=False)

Select Case rFindResult Is Nothing
Case Is = True
myCell.Offset(0, 2).Value = "n/a"
Case Else
myCell.Offset(0, 2).Value = rFindResult.Offset(ColumnOffset:=1)
End Select


Does that help?
Post back if you have more questions.
--------------------------

Regards,

Ron
Microsoft MVP (Excel)
(XL2003, Win XP)

"Eric" wrote in message
...
Referring to the post index function
Does anyone have any suggestions on how to use index function in coding
macro?

myCell.Offset(0, 2).Value =
Index(B:B [under Temp worksheet],match("Industry",A:A [under Temp
worksheet],0))

Does anyone have any suggestions?
Thanks in advance for any suggestions
Eric


"Ron Coderre" wrote:

How about just using the VBA version:

Try this:

myCell.Offset(0, 5).Value = _
Replace( _
Expression:=Sheets("Temp").Range("$J$15").Value, _
Find:="B", _
Replace:="", _
Compa=vbTextCompare)

Is that something you can work with?
Post back if you have more questions.
--------------------------

Regards,

Ron
Microsoft MVP (Excel)
(XL2003, Win XP)

"Eric" wrote in message
...
Does anyone have any suggestions on using substitute function in macro?
I would like to remove any "B" character within the return value from
Sheets("Temp").Range("$J$15").Value.

------------------------------
Macro coding
myCell.Offset(0, 5).Value = Sheets("Temp").Range("$J$15").Value
------------------------------

For example
if the return value for Sheets("Temp").Range("$J$15").Value is 25.8B,
then
I
would like to substitute "B" with "", which should return 25.8 into
myCell.Offset(0, 5).Value.
Does anyone have any suggestions?
Thanks in advance 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
Substitute function momotaro Excel Discussion (Misc queries) 4 August 28th 09 04:22 AM
'Substitute' function with wildcards [email protected] Excel Discussion (Misc queries) 1 July 22nd 09 05:42 PM
Substitute Function Question #2 Krista Excel Discussion (Misc queries) 5 April 13th 07 07:54 PM
Substitute function [email protected] Excel Discussion (Misc queries) 1 January 29th 07 07:48 PM
Substitute worksheet function SIGE Excel Programming 3 March 2nd 05 08:18 AM


All times are GMT +1. The time now is 11:47 AM.

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"