Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 154
Default STRINGS AND SUBSTRINGS !


If a cell contains a single string like "VBA is nice to know". How do I
use vba (programmatically)to write the 5 substrings "VBA" "is" "nice"
"to" "know" in five different cells (ie one substring per cell)?
Assume the main string is in cell A2, and the substrings go into cells
C2, D2, E2, F2, and G2 respectively.
Please note that I will **need** a macro.
Any help would be greatly appreciated!

Thanks
Jay Dean


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default STRINGS AND SUBSTRINGS !

Hi Jay,

Try:

Sub Tester()
Dim Sstr As String
Dim vArr As Variant
Dim rng As Range
Dim i As Long

Set rng = Range("A2")

Sstr = rng.Value '"VBA is nice to know"

vArr = Split(Sstr)

For i = LBound(vArr) To UBound(vArr)
rng.Offset(0, i + 1).Value = vArr(i)
Next
End Sub


---
Regards,
Norman



"jay dean" wrote in message
...

If a cell contains a single string like "VBA is nice to know". How do I
use vba (programmatically)to write the 5 substrings "VBA" "is" "nice"
"to" "know" in five different cells (ie one substring per cell)?
Assume the main string is in cell A2, and the substrings go into cells
C2, D2, E2, F2, and G2 respectively.
Please note that I will **need** a macro.
Any help would be greatly appreciated!

Thanks
Jay Dean


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default STRINGS AND SUBSTRINGS !

Hi Jay,

The Split function was introduced in xl2k. If you are using an earlier
version, post back for a workaround.

---
Regards,
Norman



"Norman Jones" wrote in message
...
Hi Jay,

Try:

Sub Tester()
Dim Sstr As String
Dim vArr As Variant
Dim rng As Range
Dim i As Long

Set rng = Range("A2")

Sstr = rng.Value '"VBA is nice to know"

vArr = Split(Sstr)

For i = LBound(vArr) To UBound(vArr)
rng.Offset(0, i + 1).Value = vArr(i)
Next
End Sub


---
Regards,
Norman



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 154
Default STRINGS AND SUBSTRINGS !


Norman-
I am using officeXP, and thanks a boat load! This is excellent!! I love
the fact that the function actually returns an array.

Thanks again.
Jay Dean


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
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
Macro to apply parsing rules for strings and list the substrings Luciano Paulino da Silva Excel Worksheet Functions 25 May 3rd 09 11:53 AM
sum wrt substrings! via135 Excel Worksheet Functions 6 March 26th 06 07:06 PM
Substrings in Excel? mzafar Excel Discussion (Misc queries) 3 February 28th 06 06:55 PM
Searching for Substrings Within Strings Tiziano Excel Discussion (Misc queries) 8 January 6th 05 03:09 AM
Finding substrings within a string Gaston[_6_] Excel Programming 3 February 2nd 04 06:35 AM


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