Results 1 to 3 of 3

insert appropriate number of blank spaces in cells B through H

Threaded View

  1. #1
    Registered User
    Join Date
    07-23-2014
    Location
    portland, or
    MS-Off Ver
    microsoft 2010
    Posts
    6

    insert appropriate number of blank spaces in cells B through H

    I am having trouble trying to figure out how to insert blank cells:
    I need to insert cells, in columns B through H, equal to the number of returned IDs in column B.

    Please take a look at the spreadsheet I attached.

    Here is the code I am using to separate the IDs in column B so that I get one ID in each A cell. When I do this it separates them great, but then I have to manually go in and insert cells down so that the rest of the rows match up with the right ID.

    Sub Macro1()
    Dim fromCol As String
    Dim toCol As String
    Dim fromRow As String
    Dim toRow As String
    Dim inVal As String
    Dim outVal As String
    Dim commaPos As Integer

    ' Copy from column B to column A.'
    fromCol = "B"
    toCol = "A"
    fromRow = "1"
    toRow = "1"

    ' Go until no more entries in column B.'
    inVal = Range(fromCol + fromRow).Value
    While inVal <> ""

    ' Go until all sub-entries used up.'
    While inVal <> ""
    Range(fromCol + fromRow).Select

    ' Extract each subentry.'
    commaPos = InStr(1, inVal, ",")
    While commaPos <> 0

    ' and write to output column.'
    outVal = Left(inVal, commaPos - 1)
    Range(toCol + toRow).Select
    Range(toCol + toRow).Value = outVal
    toRow = Mid(str(Val(toRow) + 1), 2)

    ' Remove that sub-entry.'
    inVal = Mid(inVal, commaPos + 1)
    While Left(inVal, 1) = " "
    inVal = Mid(inVal, 2)
    Wend
    commaPos = InStr(1, inVal, ",")
    Wend

    ' Get last sub-entry (or full entry if no commas).'
    Range(toCol + toRow).Select
    Range(toCol + toRow).Value = inVal
    toRow = Mid(str(Val(toRow) + 1), 2)
    inVal = ""
    Wend

    ' Advance to next source row.'
    fromRow = Mid(str(Val(fromRow) + 1), 2)
    Range(fromCol + fromRow).Select
    inVal = Range(fromCol + fromRow).Value
    Wend
    End Sub
    sample of separate.xlsm

    Any ideas?

    Thanks!
    Holly
    Last edited by hcorbitt; 08-20-2014 at 02:51 PM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Reaarange columns by number leaving blank spaces
    By Drigomaniac in forum Excel General
    Replies: 11
    Last Post: 10-22-2013, 04:32 AM
  2. [SOLVED] Cells - Blank or Contain Spaces
    By kimberlyre2000 in forum Excel General
    Replies: 14
    Last Post: 11-17-2012, 01:57 AM
  3. How to organize and insert blank cells between a huge number of data?
    By tareq in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 01-20-2011, 11:04 AM
  4. Deleting blank spaces in cells
    By Mr Gow in forum Excel General
    Replies: 4
    Last Post: 05-17-2006, 09:10 AM
  5. Fill blank cells with spaces
    By [email protected] in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 03-22-2006, 05:20 AM

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.6.0 RC 1