+ Reply to Thread
Results 1 to 5 of 5
  1. #1
    Registered User
    Join Date
    11-28-2008
    Location
    athens
    Posts
    4

    Smile Split Cell content in multiple cells

    Hallo All! I am very new to VBA Excel and i have a question. I have a sub routine which outputs some information in a cell that is separated by space. Something like that: "asda asda efrrwe werw 234 sfds". I just just to place each one of them in different cells! Could you help me out?! (i am not so into programming..)
    Thanks!

  2. #2
    Forums Administrator royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    24,447
    Can you show your existing code, remember to use Code Tags
    Hope that helps.

    RoyUK
    --------
    If you are pleased with a member's answer then use the Star icon to rate it, if you are pleased enough to part with cash consider a donation to Children in Need

    For Excel consulting, free examples and tutorials visit Excel Consulting-Excel VBA
    Check out the free Excel Toolbar

    New members please read & follow the Forum Rules

    Remember to mark your questions Solved and rate the answer(s)


    Code Tags: Make your code easier for us to read

  3. #3
    Valued Forum Contributor
    Join Date
    11-11-2008
    Location
    Euro
    MS-Off Ver
    2003, 2007
    Posts
    355
    Quote Originally Posted by pomolo View Post
    Hallo All! I am very new to VBA Excel and i have a question. I have a sub routine which outputs some information in a cell that is separated by space. Something like that: "asda asda efrrwe werw 234 sfds". I just just to place each one of them in different cells! Could you help me out?! (i am not so into programming..)
    Thanks!
    You should used Split - VBA function


    Function Split(Expression As String, [Delimiter], [Limit As Long = -1], [Compare As VbCompareMethod = vbBinaryCompare])

    Member of VBA.Strings
    Split a string into an array

  4. #4
    Registered User
    Join Date
    11-28-2008
    Location
    athens
    Posts
    4

    code..

    Quote Originally Posted by royUK View Post
    Can you show your existing code, remember to use Code Tags
    This is basically an example code that i use together with imacro program. It reads a list of company names (companyname) and for every one of the list outputs a stock value.If you chose to output more than one value for every company name you get all infos in the same cell separated by space.
    Could you help me out output those values, one in each cell?

    Thanks Again for your quick reply!

    pomolo

    Code:
    Option Explicit
      
    Private Sub CommandButton1_Click()
     
      MsgBox "This script demonstrates how to read data from an Excel sheet and using this, capture information from a website."
      
      Dim iim1, iret, row, totalrows
         
      Set iim1 = CreateObject("imacros")
      iret = iim1.iimInit
      iret = iim1.iimDisplay("Submitting Data from Excel")
      
      'Insert todays date
      Cells(1, 2).Value = Date
         
      'Navigate to the site and extract the first price
      row = 2
      'Set the variable
      iret = iim1.iimSet("-var_companyname", Cells(row, 1).Value)
      'Set the display
      iret = iim1.iimDisplay("Row# " + CStr(row))
      'Run the macro
      iret = iim1.iimPlay("VBA-StockSearch1")
      If iret < 0 Then
          MsgBox iim1.iimGetLastError()
      End If
      Cells(row, 2).Value = Replace(iim1.iimGetLastExtract(), "[EXTRACT]", " ")

  5. #5
    Forums Administrator royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    24,447
    I can't test the code, it's not working on my computer. You should not really give a variable a name like Row, it may cause problems

    Try this untested but it might work. 10 is only a guess for the rows
    Code:
    Private Sub CommandButton1_Click()
        MsgBox "This script demonstrates how to read data from an Excel sheet and using this, capture information from a website."
    
        Dim iim1, iret
        Dim totalrows As Long
        Dim rw     As Long
    
        Set iim1 = CreateObject("imacros")
        iret = iim1.iimInit
        iret = iim1.iimDisplay("Submitting Data from Excel")
    
        'Insert todays date
        Cells(1, 2).Value = Date
    
        'Navigate to the site and extract the first price
        For rw = 2 To 10
            'Set the variable
            iret = iim1.iimSet("-var_companyname", Cells(rw, 1).Value)
            'Set the display
            iret = iim1.iimDisplay("rw# " + CStr(rw))
            'Run the macro
            iret = iim1.iimPlay("VBA-StockSearch1")
            If iret < 0 Then
                MsgBox iim1.iimGetLastError()
            End If
            Cells(rw, 2).Value = Replace(iim1.iimGetLastExtract(), "[EXTRACT]", " ")
        Next rw
    Hope that helps.

    RoyUK
    --------
    If you are pleased with a member's answer then use the Star icon to rate it, if you are pleased enough to part with cash consider a donation to Children in Need

    For Excel consulting, free examples and tutorials visit Excel Consulting-Excel VBA
    Check out the free Excel Toolbar

    New members please read & follow the Forum Rules

    Remember to mark your questions Solved and rate the answer(s)


    Code Tags: Make your code easier for us to read

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.2.0