Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
ina ina is offline
external usenet poster
 
Posts: 120
Default if statement problem

Hello all,

I have a problem he

For each cell in my range I would like to look for this words:
Some value has the word EUR and others USD.

If (Intstr = Application.WorksheetFunction.Search("USD",
MyCell.Value)) Then
ActiveCell.Offset(0, 2).Value = Mid(MyCell.Value, 1, Intstr
- 1)

ElseIf (Intstr = Application.WorksheetFunction.Search("EUR",
MyCell.Value)) Then
ActiveCell.Offset(0, 2).Value = Mid(MyCell.Value, 1, Intstr
- 1)

End If

I have an error here because it executes the two if and the same time.


Thanks,

Ina

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default if statement problem

ilocU = Instr(1,MyCell.Value,"USD",vbTextcompare)
ilocE = Instr(1,MyCell.Value,"EUR",vbTextcompare)
if ilocU 0 then
ActiveCell.Offset(0, 2).Value = Mid(MyCell.Value, 1, IlocU - 1)
elseif iLocE 0 then
ActiveCell.Offset(0, 2).Value = Mid(MyCell.Value, 1, iLocE - 1)
End If

--
Regards,
Tom Ogilvy


"ina" wrote:

Hello all,

I have a problem he

For each cell in my range I would like to look for this words:
Some value has the word EUR and others USD.

If (Intstr = Application.WorksheetFunction.Search("USD",
MyCell.Value)) Then
ActiveCell.Offset(0, 2).Value = Mid(MyCell.Value, 1, Intstr
- 1)

ElseIf (Intstr = Application.WorksheetFunction.Search("EUR",
MyCell.Value)) Then
ActiveCell.Offset(0, 2).Value = Mid(MyCell.Value, 1, Intstr
- 1)

End If

I have an error here because it executes the two if and the same time.


Thanks,

Ina


  #3   Report Post  
Posted to microsoft.public.excel.programming
ina ina is offline
external usenet poster
 
Posts: 120
Default if statement problem

Thanks you a lot.

Could you explain me why ilocU and ilocE. I am newbie in VBA :)

Ina

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default if statement problem

any variable would do. I use iloc out of habit. i for integer (although I
would probably dim them as Long), Loc for location (location in the string)

the U was for USD
the E was for EUR

In summary, no special significance for ilocE or iLocU

If you mean what do they do, then the Instr function returns the location in
the string where the substring is found. If not found, it returns zero. So
ilocU and ilocE just store the result of instr.

--
Regards,
Tom Ogilvy


--
Regards,
Tom Ogilvy



"ina" wrote:

Thanks you a lot.

Could you explain me why ilocU and ilocE. I am newbie in VBA :)

Ina


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 400
Default if statement problem

Why are you using Instr, a VBA keyword as a variable name?

Try:

If 0< Instr(MyCell.Value,"USD") then ActiveCell.Offset(0, 2).Value =
Mid(MyCell.Value, 1, Intstr(MyCell.Value,"USD")- 1)

If 0< Instr(MyCell.Value,"EUR") then ActiveCell.Offset(0, 2).Value =
Mid(MyCell.Value, 1, Intstr(MyCell.Value,"EUR")- 1)

i.e. 2 completely separate/independent statements.

"ina" wrote:

Hello all,

I have a problem he

For each cell in my range I would like to look for this words:
Some value has the word EUR and others USD.

If (Intstr = Application.WorksheetFunction.Search("USD",
MyCell.Value)) Then
ActiveCell.Offset(0, 2).Value = Mid(MyCell.Value, 1, Intstr
- 1)

ElseIf (Intstr = Application.WorksheetFunction.Search("EUR",
MyCell.Value)) Then
ActiveCell.Offset(0, 2).Value = Mid(MyCell.Value, 1, Intstr
- 1)

End If

I have an error here because it executes the two if and the same time.


Thanks,

Ina




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
IF Statement Problem SixBowls Excel Discussion (Misc queries) 4 December 11th 09 05:33 PM
If statement problem Scott@CW Excel Discussion (Misc queries) 1 April 26th 07 03:40 PM
IF STATEMENT PROBLEM Manjit Gosal Excel Worksheet Functions 4 November 10th 05 05:40 PM
IF Statement problem trixma New Users to Excel 3 September 27th 05 06:36 AM
If Statement Problem TB via OfficeKB.com Excel Worksheet Functions 2 June 29th 05 10:03 PM


All times are GMT +1. The time now is 12:13 PM.

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

About Us

"It's about Microsoft Excel"