LString=” TechOnTheNet.com”
LArray = Split(LString, ".")
LArray() = Split(LString, ".")
LArray(i) = Split(LString, ".")
Are the above CODEs correct? Can someone explain or use examples?
LString=” TechOnTheNet.com”
LArray = Split(LString, ".")
LArray() = Split(LString, ".")
LArray(i) = Split(LString, ".")
Are the above CODEs correct? Can someone explain or use examples?
It is highly recommended that you have Option Explicit at the top of all code Modules.
Required:Dim LArray As Variant 'OR Dim LArray 'Is Variant when not specified as anything.See also: http://www.snb-vba.eu/VBA_Arrays_en.htmlDim Lstring As String LString = ”TechOnTheNet.com, TechOnTheWeb.com, TechAndTheNet.com” LArray = Split(LString, ".com, ") 'LArray(0) = TechOnTheNet 'LArray(1) = TechOnTheWeb 'LArray(2) = TechAndTheNet
PS: Why is that the wrong value for LArray(2)?
Last edited by SamT; 07-22-2017 at 08:06 AM.
I expect the student to do their homework and find all the errrors I leeve in.
Please take the time to read the Forum FAQ
LArray(2) would hold TechAndTheNet.com with this code!
will work.LArray = Split(Replace(Replace(Lstring, ".com", ""), " ", ""), ",")
____________________________________________
Nihil simul inventum est et perfectum
Abusus non tollit usum
Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
James Thurber
Hi Bob
That gives me "TechAndTheNet"
For "TechAndTheNet.com" try LArray = Split(Replace(Lstring, " ", ""), ",")
MVP (Excel 2008-2010)
Post a workbook with sample data and layout if you want a quicker solution.
To help indent your macros try Smart Indent
Please remember to mark threads 'Solved'
If you just want to separate the "TechOnTheNet" from the "com', something like this
That won't work if there are dots in the first part, so you can try thisOption Explicit Sub SplitDemo() Dim LArray As Variant Dim LString As String LString = "TechOnTheNet.com" LArray = Split(LString, ".") MsgBox LArray(0) MsgBox LArray(1) End Sub
Sub SplitDemo2() Dim i As Long Dim LString As String Dim s1 As String, s2 As String LString = "Tech.On.The.Net.com" i = InStrRev(LString, ".") s1 = Left(LString, i - 1) s2 = Right(LString, Len(LString) - i) MsgBox s1 MsgBox s2 End Sub
---------------------------------------------------------------------------------------------------------------------
Paul
Remember: Tell us WHAT you want to do, not HOW you think you want to do it
1. Use [CODE] ....[/CODE ] Tags for readability
[CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
2. Upload an example
Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
3. Mark the thread as [Solved] when you have an answer
Thread Tools (on the top right corner, above the first message)
4. Read the Forum FAQ, especially the part about cross-posting in other forums
http://www.vbaexpress.com/forum/faq...._new_faq_item3
sub M_snb() c00="TechOnTheNet.com" msgbox typename(c00) msgbox vartype(c00) msgbox isarray(c00) msgbox ubound(split(c00,".")) msgbox lbound(split(c00,".")) sn=split(c00,".") msgbox typename(sn) msgbox vartype(sn) msgbox isarray(sn) msgbox sn(0) msgbox sn(1) msgbox sn(lbound(sn)) msgbox sn(ubound(sn)) msgbox split(c00,".")(0) msgbox split(c00,".")(1) end sub
Last edited by mdmackillop; 07-22-2017 at 07:24 AM. Reason: Missing brackets added.
I probably don't have enough basic knowledge, so asked a stupid question. LArray was declared variant ,
LArray = Split(LString, ".") ----->It is correct.
LArray() = Split(LString, ".") ----->Wrong.Except LArray() was declared.
LArray(i) = Split(LString, ".")------>Wrong. Same above.
I expect the student to do their homework and find all the errrors I leeve in.
Please take the time to read the Forum FAQ
SamT forgot to mention that you can mark your thread solved by using [Thread Tools] above your first post
---------------------------------------------------------------------------------------------------------------------
Paul
Remember: Tell us WHAT you want to do, not HOW you think you want to do it
1. Use [CODE] ....[/CODE ] Tags for readability
[CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
2. Upload an example
Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
3. Mark the thread as [Solved] when you have an answer
Thread Tools (on the top right corner, above the first message)
4. Read the Forum FAQ, especially the part about cross-posting in other forums
http://www.vbaexpress.com/forum/faq...._new_faq_item3
MVP (Excel 2008-2010)
Post a workbook with sample data and layout if you want a quicker solution.
To help indent your macros try Smart Indent
Please remember to mark threads 'Solved'