+ Reply to Thread
Results 1 to 5 of 5

How to write a copy loop in VBA based on what columns contain values.

  1. #1
    Registered User
    Join Date
    03-01-2015
    Location
    Melbourne
    MS-Off Ver
    2007
    Posts
    2

    How to write a copy loop in VBA based on what columns contain values.

    I would like to know how to write a copy loop in VBA based on what columns contain values.

    Currently I have a submit button/macro for each column individually which copies one column from one sheet (Questionnaire) to another (Data). However I would like to submit all the columns where there is data in the columns.


    How do I re-write this so that it copies column B then C and so on, if there is data in the column, then end? (Assuming when you reach a blank column are is no more columns to copy)


    Sub SUMBIT()
    '
    Sheets("Data").Select
    Columns("B:B").Select
    Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
    Sheets("Questionnaire").Select
    Columns("B:B").Select
    Selection.Copy
    Sheets("Data").Select
    Range("B1").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=False
    Sheets("Questionaire").Select
    Range("B1").Select
    End Sub

  2. #2
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: How to write a copy loop in VBA based on what columns contain values.

    There is a problem writing here suddenly.
    Attached Files Attached Files
    Last edited by mehmetcik; 04-22-2015 at 05:26 AM.
    My General Rules if you want my help. Not aimed at any person in particular:

    1. Please Make Requests not demands, none of us get paid here.

    2. Check back on your post regularly. I will not return to a post after 4 days.
    If it is not important to you then it definitely is not important to me.

  3. #3
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,485

    Re: How to write a copy loop in VBA based on what columns contain values.

    Attaching a sample workbook enables others to work on your problem:

    To attach a sample workbook. Make sure there is just enough data to make it clear what is needed. Include BEFORE/AFTER sheets if needed to show the process you're trying to complete or automate. Remember to desensitize the data.

    Click on GO ADVANCED and use the paperclip icon to open the upload window.

    View Pic

  4. #4
    Registered User
    Join Date
    03-01-2015
    Location
    Melbourne
    MS-Off Ver
    2007
    Posts
    2

    Re: How to write a copy loop in VBA based on what columns contain values.

    Attached is my spreadsheet.

    Thanks for the reply however currently I am not sure if the above sheet helps me at all.


    Questionnaire.xlsm

  5. #5
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,485

    Re: How to write a copy loop in VBA based on what columns contain values.

    If you want to keep a data sheet, the data should be in rows instead of columns, here is my version on how you should have your sheet laid out. When you clcik the button the data goes to the data sheet in rows.
    Attached Files Attached Files

+ 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. [SOLVED] How to write a code within a loop to copy and paste rows on to another Sheet
    By swade730 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-24-2014, 08:40 PM
  2. Loop based on two values and then Copy based on numbers between the two values
    By mintsaucesheep in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 08-20-2013, 09:43 AM
  3. [SOLVED] Copy/Paste multiple columns as values based on another columns criteria
    By Dgp2012 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 07-28-2013, 06:50 AM
  4. Loop-copy irregular columns values to new table
    By leonnord in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-29-2007, 06:54 PM
  5. Need to loop through rows and copy values based on criteria
    By Nice in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-21-2005, 08:49 AM

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