+ Reply to Thread
Results 1 to 5 of 5

To move Data rows to columns against one cell so can write separate SQL insert statments

  1. #1
    Registered User
    Join Date
    03-14-2014
    Location
    United Kingdom
    MS-Off Ver
    Excel 2010
    Posts
    4

    Smile To move Data rows to columns against one cell so can write separate SQL insert statments

    I have scoured the web to move data from a row
    ie

    name no1 no2 no3 no4 ...no8
    . . . . .
    . . . . .
    . . . . .
    to
    name no1
    name no2
    name no3

    So then you can write SQL inserts against each line and insert into a database.

    On this forum I have seen to go from columns to rows but not the other way round!

    I learnt some VBA from excel pratique site and wrote the vba script to do it. Never done VBA before this but hit the fustration of developing which is why I dont like coding.
    Had to use 4 counters and solve some sequence math. As you have to count in 8s for the columns.

    If anyone has a better easier to do this then please advise.Samplenamesnumbersrowsforexcelforum.xlsx

    Have attached a sample spreadsheet, obviously I have modified the numbers and names to protect privacy.
    Last edited by hadster016; 03-18-2014 at 09:48 AM. Reason: marking solved

  2. #2
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: To move Data rows to columns against one cell so can write separate SQL insert statmen

    Does this help?

    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    03-14-2014
    Location
    United Kingdom
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: To move Data rows to columns against one cell so can write separate SQL insert statmen

    Wow yours is neat, works on the same columns of data and removes the blanks?
    Here is my solution. Mine writes to new columns but you still have to remove blanks I just used the filter.

    Where can I learn more about the commands you used here?

    I had to sort out the relationship in mine for
    A2 – K2
    A3 – K10
    A4 – K18
    A5 – K26
    A6 – K34
    , will post this in separate reply.

    Please Login or Register  to view this content.
    Last edited by hadster016; 03-18-2014 at 09:42 AM.

  4. #4
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: To move Data rows to columns against one cell so can write separate SQL insert statmen

    Please comply with Forum Rule No. 3 - when posting. Looks like you have a working solution so comply with Forum Rule No. 9 as well:


    9. Acknowledge the responses you receive, good or bad. If your problem is solved, please say so clearly, and mark your thread as Solved: Click Thread Tools above your first post, select "Mark your thread as Solved". Or click the Edit button on your first post in the thread, Click Go Advanced, select [SOLVED] from the Prefix dropdown, then click Save Changes. If more than two days have elapsed, the Dropdown option or Edit button will not appear -- ask a moderator to mark it.

    In my code I used the x variable to move down rows, and the i variable to move accross the Columns for each row. Then I was able to identify cells which were not blank and added a row beneath the working row. I used the rcell range variable to delete empty cells. You can pretty much pick up any VBA book, search the Forums such as this one or Google to advance your knowledge of how the variables work. Your code looks good, it just uses a different approach.

  5. #5
    Registered User
    Join Date
    03-14-2014
    Location
    United Kingdom
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: To move Data rows to columns against one cell so can write separate SQL insert statmen

    Yes your posts are good and have been helpfull, I feel I can learn from the code you gave me to do things more efficiently as your code is much faster than mine took to run.

    The excel pratique site did say using arrays was fast?

    Also you did'nt have to do any math in your like mine I had to come up with a formula for the series k = (8x) - 14.
    If anyone wants the workings let me know and I'll post that here too.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 2
    Last Post: 10-22-2013, 06:01 AM
  2. Replies: 7
    Last Post: 07-19-2013, 10:55 AM
  3. [SOLVED] How to separate cell values and insert into new rows
    By dj7616 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-22-2013, 09:10 PM
  4. Replies: 7
    Last Post: 09-07-2011, 02:30 PM
  5. Help! Need to move rows to separate worksheet if cell values match a value in range
    By nzamparo in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 07-25-2011, 12: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