I want to know the macro or query to split the string in one single colunm and insert those into multiple colunms(that may be a sentence)
like for example
colunm1 contains:
1234 daily !@#$(these words are separated by space)
these things must be splited in to
1234,daily,!@#$ and inserted into three different colunms
colunm2 colunm3 colunm4
1234 daily !@#$
these colunms are in same table.
12 4521
One way to do this is to use a parsing function like the one below. This function is passed a string and a list of delimeters (such as " " for space). It will then go through the string and split the string into an array. Once you have the array use a for...next loop to populate the remaining fields.
Here is the code of the parsing function. It shouldn't need much if any editing to get working: -
Public Function parse(ByVal inString, Optional ByVal delimiters)
-
'Take a string, and return it as a one dimensional array
-
' of individual values as delimited by any of several
-
' characters. None of those characters are returned in
-
' the result. Provide a default list of delimiters, which
-
' should come from registry. But allow override.
-
-
Dim delimitList, oneChar, aWord, codeCount
-
Dim arrayCodes()
-
-
If IsMissing(delimiters) Then
-
'We should get these from Registry
-
delimitList = " ,/!|"
-
'Characters recognized as delimiters
-
-
Else
-
delimitList = delimiters
-
'user can override if needed
-
-
End If
-
Dim i, j, k
-
i = Len(inString)
-
For j = 1 To i
-
'Read one character at a time
-
-
oneChar = VBA.Strings.Mid(inString, j, 1)
-
k = InStr(delimitList, oneChar)
-
'Is this one a delimiter?
-
If k = 0 Then
-
aWord = aWord & oneChar
-
'If is isn't, add to the current word
-
End If
-
If k <> 0 Or j = i Then
-
'If it is, or if we're finished
-
If aWord > "" Then
-
codeCount = codeCount + 1
-
ReDim Preserve arrayCodes(codeCount)
-
arrayCodes(codeCount) = aWord
-
'Save new word
-
aWord = ""
-
End If
-
End If
-
Next j
-
parse = arrayCodes
-
'Return the array
-
End Function
-
Hope this helps
- Minion -
hi minion
thankyou for your response
But i am not understanding this please give a detailed explination
on this ,actually i do not know anything about macro please help me
You really need to provide a little more information. Is the original string always going to be three words long? Are the words always going to be separated by a comma?
Welcome, both of you, to TheScripts!
Linq ;0)>
I want to know the macro or query to split the string in one single colunm and insert those into multiple colunms(that may be a sentence)
like for example
colunm1 contains:
1234 daily !@#$(these words are separated by space)
these things must be splited in to
1234,daily,!@#$ and inserted into three different colunms
colunm2 colunm3 colunm4
1234 daily !@#$
these colunms are in same table.
Here is compact code that will work as long as you have only 3 values in [Column1] separated by spaces. It assumes your Table Name is tblTest, and your Field Names are [Column1], [Column2], [Column3], and [Column4] where [Column1] contains the multiple values. Any questions, feel free to ask. -
Dim MyDB As DAO.Database, MyRS As DAO.Recordset
-
Dim varSplit As Variant, intCounter As Integer
-
-
Set MyDB = CurrentDb()
-
Set MyRS = MyDB.OpenRecordset("tblTest", dbOpenDynaset)
-
-
If MyRS.RecordCount > 0 Then
-
Do While Not MyRS.EOF
-
varSplit = Split(MyRS![Column1], " ")
-
MyRS.Edit
-
For intCounter = 0 To UBound(varSplit) 'will be 2
-
MyRS![Column2] = varSplit(0)
-
MyRS![Column3] = varSplit(1)
-
MyRS![Column4] = varSplit(2)
-
Next
-
MyRS.Update
-
MyRS.MoveNext
-
Loop
-
End If
-
-
MyRS.Close
-
Set MyRS = Nothing
You really need to provide a little more information. Is the original string always going to be three words long? Are the words always going to be separated by a comma?
Welcome, both of you, to TheScripts!
Linq ;0)>
hi,
the string length will be differing,And the string is not separated by comma,It is separated by SPACE
Thank You
Here is compact code that will work as long as you have only 3 values in [Column1] separated by spaces. It assumes your Table Name is tblTest, and your Field Names are [Column1], [Column2], [Column3], and [Column4] where [Column1] contains the multiple values. Any questions, feel free to ask. -
Dim MyDB As DAO.Database, MyRS As DAO.Recordset
-
Dim varSplit As Variant, intCounter As Integer
-
-
Set MyDB = CurrentDb()
-
Set MyRS = MyDB.OpenRecordset("tblTest", dbOpenDynaset)
-
-
If MyRS.RecordCount > 0 Then
-
Do While Not MyRS.EOF
-
varSplit = Split(MyRS![Column1], " ")
-
MyRS.Edit
-
For intCounter = 0 To UBound(varSplit) 'will be 2
-
MyRS![Column2] = varSplit(0)
-
MyRS![Column3] = varSplit(1)
-
MyRS![Column4] = varSplit(2)
-
Next
-
MyRS.Update
-
MyRS.MoveNext
-
Loop
-
End If
-
-
MyRS.Close
-
Set MyRS = Nothing
Hi
thankyou for your reply
In the Colunm1 string is not constant and It varies alway
thankyou
Here is compact code that will work as long as you have only 3 values in [Column1] separated by spaces. It assumes your Table Name is tblTest, and your Field Names are [Column1], [Column2], [Column3], and [Column4] where [Column1] contains the multiple values. Any questions, feel free to ask. -
Dim MyDB As DAO.Database, MyRS As DAO.Recordset
-
Dim varSplit As Variant, intCounter As Integer
-
-
Set MyDB = CurrentDb()
-
Set MyRS = MyDB.OpenRecordset("tblTest", dbOpenDynaset)
-
-
If MyRS.RecordCount > 0 Then
-
Do While Not MyRS.EOF
-
varSplit = Split(MyRS![Column1], " ")
-
MyRS.Edit
-
For intCounter = 0 To UBound(varSplit) 'will be 2
-
MyRS![Column2] = varSplit(0)
-
MyRS![Column3] = varSplit(1)
-
MyRS![Column4] = varSplit(2)
-
Next
-
MyRS.Update
-
MyRS.MoveNext
-
Loop
-
End If
-
-
MyRS.Close
-
Set MyRS = Nothing
Hi,
Can you give this same thing to use in excel
And the other thing is my string in the column1 will be varying
it may be
case1:hi john hw r u
case2:wt r u doning
case3 can we meet today or not
case4:when can we meet so
like the above the strings in my column1 will be changing,
if you can give me solution for this please give me in access and excel. OR
please give the previous solution to use in EXCEL
thankyou
Hi,
Can you give this same thing to use in excel
And the other thing is my string in the column1 will be varying
it may be
case1:hi john hw r u
case2:wt r u doning
case3 can we meet today or not
case4:when can we meet so
like the above the strings in my column1 will be changing,
if you can give me solution for this please give me in access and excel. OR
please give the previous solution to use in EXCEL
thankyou
- I'm asuming that your Fields are already defined in your Table namely: Column1, Column2, Column3, Column4, Column5, etc. Is this the case, and if so how many pre-defined Columns exist in the Table?
- You previously stated that the values in Column1 could also be delimited by a Comma in addition to a space, does this still hold?
- Would the Delimiter be consistent for all the Records in a Table, or could you possibly have the scenario listed below?
- Record 1 Value1, Value2, Value3, etc. 'Comma Delimiter
-
Record 2 Value1 Value2 Value3, etc 'Space Delimiter
Two things:
First, we've all been concentrating on parsing your string and noone's actually asked: Exactly what are you trying to do here? As ADezii asked, how many columns are you going to have to cover ever possibilty in Column1?
Secondly, you have cost a number of experts here a great deal of time! You initially stated your problem, showing an example string with three parts, separated by commas. When asked if this is the format the string will always be in, you responded a day and a half later, saying that no, the string will vary in length and no, despite your example being separated by commas, they will actually be separated by spaces! Then you come back again, demanding an answer to the problem using Excel!
Please take the time to read the Posting Guidelines paying special attention to the section titled “ Give as much detail as possible!”
Linq ;0)>
Two things:
First, we've all been concentrating on parsing your string and noone's actually asked: Exactly what are you trying to do here? As ADezii asked, how many columns are you going to have to cover ever possibilty in Column1?
Secondly, you have cost a number of experts here a great deal of time! You initially stated your problem, showing an example string with three parts, separated by commas. When asked if this is the format the string will always be in, you responded a day and a half later, saying that no, the string will vary in length and no, despite your example being separated by commas, they will actually be separated by spaces! Then you come back again, demanding an answer to the problem using Excel!
Please take the time to read the Posting Guidelines paying special attention to the section titled “Give as much detail as possible!”
Linq ;0)>
Nicely said, missinglinq.
Two things:
First, we've all been concentrating on parsing your string and noone's actually asked: Exactly what are you trying to do here? As ADezii asked, how many columns are you going to have to cover ever possibilty in Column1?
Secondly, you have cost a number of experts here a great deal of time! You initially stated your problem, showing an example string with three parts, separated by commas. When asked if this is the format the string will always be in, you responded a day and a half later, saying that no, the string will vary in length and no, despite your example being separated by commas, they will actually be separated by spaces! Then you come back again, demanding an answer to the problem using Excel!
Please take the time to read the Posting Guidelines paying special attention to the section titled “Give as much detail as possible!”
Linq ;0)>
Hi,
Actually,
1.I will get a string into my first column1
2.I don't no its length
3.I am having n-number of columns in my table or sheet
4.My delimiter is "space"
5.My database may be access or excel
So please suggest me the solution.
thankyou
Hi,
Actually,
1.I will get a string into my first column1
2.I don't no its length
3.I am having n-number of columns in my table or sheet
4.My delimiter is "space"
5.My database may be access or excel
So please suggest me the solution.
thankyou
Thank you for clearifing what it is your looking for somewhat. However, the medium for your database will greatly determine what type of solution is produced. If we were to give you a suggestion for how to solve your problem in access it would differ from one given for access. You also mentioned that you have limited to no knowledge of VBA or Macros so any solution you are given will be a challenge for you to implement. These are just a couple of the challenges still facing your situation; however I'll keep working on a solution that you should be able to utilize as more information is made available. Namely we need to know exactly what you have, what you will need, and what program you will need it for as the code will differ quite a bit.
Keep us posted.
- Minion -
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Steven Bethard |
last post by:
I feel like this has probably been answered before, but I couldn't
find something quite like it in the archives. Feel free to point me
somewhere if you know where this has already been answered.
...
|
by: mike |
last post by:
Hello all,
any advice or links to pages about how to have multiple language asp
pages? For example, you have a database driven website that you want
customers around the world to use. How do...
|
by: Sreejith S S Nair |
last post by:
hi there,
I have a panel control which contain more than 10 label
controls. these label controls are added dynamically by user.
In this application user can slit a control into not less than...
|
by: Sreejith S S Nair |
last post by:
hi,
Setp one.
i have one panel control in my form. I am spliting this panel control into
two part say working region and holding region. This spliting is only logic
spliting.
That is i...
|
by: Diffident |
last post by:
Hello All,
I have a string of around 150 characters.
string test = "asjhdkashdkjahsdjkhaskjdhaskjdhasjdhasd........."; //(upto
150 characters)
I want to split the above string into multiple...
|
by: Diffident |
last post by:
Dear Bruce,
Can you please explain me how compiler would be able to optimize "+" for the
below code?
The reason why I did not want to use string concatenation was that I wanted
it to be a...
|
by: dan |
last post by:
within a loop i am building a sql insert statement to run against my
(programatically created) mdb. it works but it seems unreasonably SLOW!
Sorry, dont have the code here but the jist is very...
|
by: Mersilla |
last post by:
Dear All,
I am currently new to perl and is experiencing difficulties with splitting and array with multiple conditions.
For example ,
I would like to spilt an element, which contains one or...
|
by: kalia |
last post by:
I have a text file and i want to Split the file into mulitple files based off the city and then create new files with the city name.
I am able to read the file and also chnaged the semi colon to a...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |