Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default InStr function

Hi all. I am new to Excel VBA, Here's my problem.
I have a string in a cell for example: "this is my string : category"
What I need to be able to do is find the position of the ":" and return it
as an integer. I understand you can use the InStr function to do this. But....
How do I pass the result onto the spreadsheet itself?
Further to that, how do I use this same function for 50 more rows below?
I have tried using in the cell formula bar something like
"=MyFunctionName(CurrentCell)"
But all I keep getting in the cell is "#NAME!". Any ideas? Thank You.

Ash.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,440
Default InStr function

Hi Ash,

You don't need VBA for that:

=FIND(":",A1)

returns 19

If you insist on using VBA, don't use a Sheet Module, use a standard module (in the VB editor: InsertModule)

--
Kind regards,

Niek Otten
Microsoft MVP - Excel

"AshGrant" wrote in message ...
| Hi all. I am new to Excel VBA, Here's my problem.
| I have a string in a cell for example: "this is my string : category"
| What I need to be able to do is find the position of the ":" and return it
| as an integer. I understand you can use the InStr function to do this. But....
| How do I pass the result onto the spreadsheet itself?
| Further to that, how do I use this same function for 50 more rows below?
| I have tried using in the cell formula bar something like
| "=MyFunctionName(CurrentCell)"
| But all I keep getting in the cell is "#NAME!". Any ideas? Thank You.
|
| Ash.


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default InStr function

Ah excellent thanks for that, I'll give it a try and let you know how I get on!
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default InStr function

Hello again,
That worked brilliant. The only problem is, in some of the cells, a ":" is
not present, hence at the moment the result returned is "#VALUE!". How can I
prevent this? A simple IF statement of some sort?
The purpose of all this is to split a string into two different cells i.e.
Cell A1 = "Split Categories : Internal Transfer"
Needs to be converted into:
Cell A2 = "Split Categories :"
Cell A3 = "Internal Transfer"
I know to use the LEFT(A1,X) Function, but what about for the string AFTER
the ":", referenced Cell A3 above.
Hope thats not too confusing, thanks.
Ash.
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,440
Default InStr function

Hi Ash,

=IF(ISERROR(FIND(":",A1)),"",FIND(":",A1))

--
Kind regards,

Niek Otten
Microsoft MVP - Excel

"AshGrant" wrote in message ...
| Hello again,
| That worked brilliant. The only problem is, in some of the cells, a ":" is
| not present, hence at the moment the result returned is "#VALUE!". How can I
| prevent this? A simple IF statement of some sort?
| The purpose of all this is to split a string into two different cells i.e.
| Cell A1 = "Split Categories : Internal Transfer"
| Needs to be converted into:
| Cell A2 = "Split Categories :"
| Cell A3 = "Internal Transfer"
| I know to use the LEFT(A1,X) Function, but what about for the string AFTER
| the ":", referenced Cell A3 above.
| Hope thats not too confusing, thanks.
| Ash.




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,440
Default InStr function

=RIGHT(A1,LEN(A1)-FIND(":",A1))

--
Kind regards,

Niek Otten
Microsoft MVP - Excel

"AshGrant" wrote in message ...
| Hello again,
| That worked brilliant. The only problem is, in some of the cells, a ":" is
| not present, hence at the moment the result returned is "#VALUE!". How can I
| prevent this? A simple IF statement of some sort?
| The purpose of all this is to split a string into two different cells i.e.
| Cell A1 = "Split Categories : Internal Transfer"
| Needs to be converted into:
| Cell A2 = "Split Categories :"
| Cell A3 = "Internal Transfer"
| I know to use the LEFT(A1,X) Function, but what about for the string AFTER
| the ":", referenced Cell A3 above.
| Hope thats not too confusing, thanks.
| Ash.


  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default InStr function

Excellent. Many thanks Niek. Is there an address I can contact you on if I
have any further probs or should I just post here?

Thanks again,
Ash.
  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,440
Default InStr function

Complex calculations with lots of dependencies are best done in Excel, because you don't have to keep track of all the
dependencies yourself.
It's also a matter of taste. Some programmers insist that calculations can easily be done in COBOL. Poor guys.....

--
Kind regards,

Niek Otten
Microsoft MVP - Excel

"AshGrant" wrote in message ...
| Hi again, no problem this time just a simple question.
| I am an advanced user with Access 2000, been programming VBA and designing
| accounts applications for 2 yrs now.
| Just wondering though, I want to improve my Excel skills and maybe create
| some useful apps in Excel. But whatever I think of, I always drift back to
| Access because it always seems to be easier and quicker.
| What would you typically use Excel for? I don't mean simple accounts
| spreadsheets, i'm talking more in terms of full applications with features
| aplenty.
| Bit confused on this one. It just seems that anything Excel can do, Access
| can do better...Correct me if i'm wrong.


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
Use InStr function in formula? Lee Hunter Excel Worksheet Functions 8 May 8th 23 03:45 AM
Help with VBA InStr() function EagleOne Excel Discussion (Misc queries) 10 April 12th 07 02:47 PM
InStr Function zoot Excel Programming 1 June 5th 06 03:53 AM
InStr Function Question gfh28105 Excel Programming 3 September 14th 05 02:28 AM
InStr function question [email protected] Excel Programming 9 June 28th 05 03:03 PM


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