Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 68
Default IF THEN ELSE question

Hi,

I have following code:
Sub auto()

Dim txt As String
Range("A3").Formula = "=mid(trim(a2),16,5)"
txt = Range("A3").Value

If txt = "TRIAL" Then
Application.Run ("text2colGL")
Else
If txt = "AR AG" Then
Application.Run ("txt2colAR")
Else
Application.Run ("text2col")
End If
End If

End Sub

How can I avoide placing the mid/trim function in cell A3.
If I use:
text = mid(trim(range("A2"),16,5)

it doesn't give me the same value.

Cheers,

Harold
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default IF THEN ELSE question

Option Explicit
Sub Auto()

Dim txt As String
With ActiveSheet
txt = Mid(Application.Trim(.Range("a2").Value), 16, 5)
End With

If ucase(txt) = "TRIAL" Then
Call Text2ColGL
Else
If ucase(txt) = "AR AG" Then
Call Txt2ColAR
Else
Call Text2Col
End If
End If

End Sub

You don't need application.run to call a procedure.

And if you get more choices, you may want to use "select case".

Option Explicit
Sub Auto2()

Dim txt As String
With ActiveSheet
txt = Mid(Application.Trim(.Range("a2").Value), 16, 5)
End With

select case ucase(txt)
case is = "TRIAL"
Call Text2ColGL
case is = "AR AG"
Call Txt2ColAR
case else
Call Text2Col
end select

End Sub

It can make it easier to read the code later.


mohavv wrote:

Hi,

I have following code:
Sub auto()

Dim txt As String
Range("A3").Formula = "=mid(trim(a2),16,5)"
txt = Range("A3").Value

If txt = "TRIAL" Then
Application.Run ("text2colGL")
Else
If txt = "AR AG" Then
Application.Run ("txt2colAR")
Else
Application.Run ("text2col")
End If
End If

End Sub

How can I avoide placing the mid/trim function in cell A3.
If I use:
text = mid(trim(range("A2"),16,5)

it doesn't give me the same value.

Cheers,

Harold


--

Dave Peterson
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
ANother Question N.F[_2_] Excel Discussion (Misc queries) 1 June 30th 07 12:53 AM
Not sure how to do this, not even sure how to ask the question clearly... rich Excel Worksheet Functions 4 May 7th 06 01:30 PM
Newbie Question - Subtraction Formula Question [email protected] Excel Discussion (Misc queries) 3 May 5th 06 05:50 PM
The question is an excel question that I need to figure out howto do in excel. Terry Excel Worksheet Functions 3 January 23rd 06 06:22 PM
Last question! Deadloss Excel Discussion (Misc queries) 2 December 22nd 05 11:02 PM


All times are GMT +1. The time now is 08:42 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"