Splitting of a cell value

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • shalskedar
    New Member
    • Sep 2009
    • 66

    Splitting of a cell value

    In my Application,I need to split the cell value in such a way that the each splitted values is stored as different record...
    for ex-If the value in the cell A1 is (20,43,15) then it should be stored in the Database(Ms Aceess 2003) as

    Record 1 :20

    Record 1 :43

    Record 1 :15


    How to write a function in vba so as to split the cell value without using the built in option "Text to column".

    Can any one Plz help me to do this...
  • TheSmileyCoder
    Recognized Expert Moderator Top Contributor
    • Dec 2009
    • 2322

    #2
    Access has a built in Split function.
    Asumming you have imported the date to access, in a table myTbl, with fields: Original, Field1, Field2,Field3 you could do:


    Code:
    'Open recordset
      Dim myRS as dao.Recordset
      set myRs=CurrentDb.OpenRecordset("myTbl",dbopendynaset)
    
    'Loop through records
      Do While not myRS.Eof
        myRS.Edit
        myRS!Field1=Split(myRS!Original,",")(0) 'Take first 
        myRS!Field2=Split(myRS!Original,",")(1) 'Take second 
        myRS!Field3=Split(myRS!Original,",")(2) 'Take third 
        myRs.Update
      Loop
    
    'Cleanup
       myRS.Close
       set myRS=Nothing

    Comment

    • shalskedar
      New Member
      • Sep 2009
      • 66

      #3
      Thanks...

      This data will b in the form of different columns whereas the data to be displayed should be as

      Record1-20

      Record2-43

      Record3-46

      Comment

      Working...