+ Reply to Thread
Results 1 to 5 of 5

converting pseudocode to VBA

Hybrid View

  1. #1
    Registered User
    Join Date
    03-15-2009
    Location
    NY, NY
    MS-Off Ver
    Excel 2007
    Posts
    5

    converting pseudocode to VBA

    I have a spreadsheet with 4 columns of information, then a column for a primary name, and then many columns of secondary names (with a different number of secondary names for each row).

    For rows with more than 1 secondary name, I need to create a new row with a copy of all the columns up to the secondary name for each secondary name in the row.


    A row in the spreadsheet looks like this:

    data data data data PrimaryName SecondaryName1 SecondaryName2 SecondaryName3... SecondaryNameN

    I need this row to be replaced by the following set of rows:

    data data data data PrimaryName SecondaryName1

    data data data data PrimaryName SecondaryName2

    data data data data PrimaryName SecondaryName3
    ...
    data data data data PrimaryName SecondaryNameN




    Here is some possible pseudo code for the algorithm:

    int curRow = 1
    IF (Cell(FcurRow)!=null)
    {
    * insert a duplicate of curRow below curRow
    * delete all columns after E for curRow
    * for the duplicated curRow (which is now curRow+1), shift over columns F through Z and make these columns E through Y
    }
    curRow++;
    Last edited by VBA Noob; 03-15-2009 at 02:33 PM.

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Help converting pseudocode to VBA

    To best describe or illustrate your problem you would be better off attaching a dummy workbook, the workbook should contain the same structure and some dummy data of the same type as the type you have in your real workbook - so, if a cell contains numbers & letters in this format abc-123 then that should be reflected in the dummy workbook.

    If needed supply a before and after sheet in the workbook so the person helping you can see what you are trying to achieve.

    Doing this will ensure you get the result you need!
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  3. #3
    Registered User
    Join Date
    03-15-2009
    Location
    NY, NY
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: Help converting pseudocode to VBA

    Thank you.

    Attached please find a copy of the sample data, and below what the sample data needs to look like.
    Attached Files Attached Files

  4. #4
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606

    Re: converting pseudocode to VBA

    Try this. Results in sheet2.
    Sub x()
    
    Dim rng As Range, rng2 As Range, nCol As Long
    
    Application.ScreenUpdating = False
    
    Sheet1.Activate
    
    For Each rng In Range("A1", Range("A1").End(xlDown))
        nCol = rng.End(xlToRight).Column - 4
        Set rng2 = rng.Resize(, 4)
        With Sheet2
            .Cells(Rows.Count, 1).End(xlUp)(2).Resize(nCol, 4).Value = rng2.Value
            rng.Offset(, 4).Resize(, nCol).Copy
                .Cells(Rows.Count, 5).End(xlUp)(2).Resize(nCol).PasteSpecial Transpose:=True
        End With
    Next rng
    
    Application.ScreenUpdating = True
    
    End Sub

  5. #5
    Registered User
    Join Date
    03-15-2009
    Location
    NY, NY
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: converting pseudocode to VBA

    Thank you!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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