Results 1 to 10 of 10

Continuous column copy / Non-continuous column paste (VBA)

Threaded View

macrorookie Continuous column copy /... 02-05-2014, 06:38 PM
alansidman Re: Continuous column copy /... 02-05-2014, 06:40 PM
macrorookie Re: Continuous column copy /... 02-05-2014, 08:34 PM
alansidman Re: Continuous column copy /... 02-05-2014, 08:44 PM
macrorookie Re: Continuous column copy /... 02-05-2014, 09:02 PM
alansidman Re: Continuous column copy /... 02-05-2014, 09:18 PM
macrorookie Re: Continuous column copy /... 02-05-2014, 09:27 PM
alansidman Re: Continuous column copy /... 02-05-2014, 09:47 PM
macrorookie Re: Continuous column copy /... 02-05-2014, 10:49 PM
millz Re: Continuous column copy /... 02-05-2014, 11:35 PM
  1. #1
    Forum Contributor
    Join Date
    02-05-2014
    Location
    Bay Area
    MS-Off Ver
    Microsoft 365
    Posts
    166

    Continuous column copy / Non-continuous column paste (VBA)

    Hello.

    I'm a rookie to macros/VBA and to this website/forum. I appreciate any help I can get on my question (a rookie question).

    I'm slogging my way through a macro that essentially copies specific (but non-continuous) columns of raw data from one worksheet ("data") to another worksheet ("fundings"). Both worksheets are in the same workbook. The code I listed below works (albeit, it is ugly), but I'm having a hard time pasting my data differently than how I'm copying it. What I need to do is paste the data into specific (non-continuous) columns on the destination worksheet. I'm using the Union function to copy the non-continuous columns from the raw data. This function combines the non-continuous columns and makes them look continuous. There are nine columns selected in "data" (see code below), and this data is then pasted to the first nine columns in "fundings". What I need to do is paste the results in specific columns of the destination worksheet ("fundings"). For example, I want the first-through-fourth copied columns ("A-D") to paste to the first four columns of the destination sheet (this already happens), and I want the fifth column of copied data ("G") to paste to the seventh column of the destination sheet (not working). I can't figure out how to skip columns in the pasting function.

    Apologies for being lengthy. And thanks in advance for the help.

    Dim LSearchRow As Integer
    Dim LCopyToRow As Integer
    Dim LDateToday As Date
    Dim DestinationSheetName As String
    Dim Fundings As String
    Dim CopyToRow As Integer
    
    'Macro is run based on the date that is listed on the "Company Statistics" tab.
    LDateToday = Sheets("Company Statistics").Range("D1").Value
    
    'Set the tab to where the data will be imported (from the "data" tab).
    'Make sure to change this number if the "destination" row changes.
    CopyToRowFundings = 13
    
    'Select the row from which the macro starts searching for the relevant data (in the "data" tab).
    LSearchRow = 2
    
    'Select the worksheet from which the macro will pull the data (pulling from the "data" tab).
    Sheets("Data").Select
    
    'Only reference data in the respective column/row if there is a relevant data set available (e.g., refer to a code ID).
    While Len(Range("A" & CStr(LSearchRow)).Value) > 0
    
        'Set constraints to limit the amount of data searched by the macro.
        'Refer to two tests for this function: a) the funding date compared to the relevant date, and b) the funding column has available data.
        If (Range("U" & CStr(LSearchRow)).Value) < LDateToday And (Range("U" & CStr(LSearchRow)).Value) > 0 Then
           
            'Select the specific columns on the data sheet to copy.
            'Important to note that the first range covers columns A-D and the balance are individual columns.
            Union(Range("A" & CStr(LSearchRow), "D" & CStr(LSearchRow)), Range("G" & CStr(LSearchRow)), Range("J" & CStr(LSearchRow)), Range("U" & CStr(LSearchRow)), Range("Y" & CStr(LSearchRow)), Range("AI" & CStr(LSearchRow))).Select
            
            'Copy the specific columns as a continuous set of numbers, as if the columns were immediately next to each other (which explains the Union).
            Selection.Copy
    
        'Set the rules for matching the above data to the destination worksheet.
        'The "+1" feature creates the loop.
        'The "DestinationSheetName" feature points the data to the correct worksheet.
        'Now we have copied the data, pointed it to the correct destination.
            CopyToRow = CopyToRowFundings
            CopyToRowFundings = CopyToRowFundings + 1
            DestinationSheetName = "Fundings"
              
        'Now tell the macro how to paste the data to its destination.
            Sheets(DestinationSheetName).Select
            Rows(CStr(CopyToRow) & ":" & CStr(CopyToRow)).Select
            ActiveSheet.Paste
    Last edited by alansidman; 02-05-2014 at 06:40 PM. Reason: code tags added

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Auto copy from upper cells in dis-continuous data in column
    By JawadAhmed in forum Excel - New Users/Basics
    Replies: 4
    Last Post: 04-14-2013, 09:31 AM
  2. Column contents to continuous text
    By Firemaster in forum Outlook Formatting & Functions
    Replies: 1
    Last Post: 10-16-2012, 08:12 AM
  3. [SOLVED] Ranking In a Non-Continuous Column
    By DawginAuburn in forum Excel General
    Replies: 4
    Last Post: 09-13-2012, 09:51 AM
  4. Copy not continuous ranges and paste it new word file
    By suny100 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-26-2012, 02:16 PM
  5. add cells conditionaly not in continuous row or column
    By loganinc6 in forum Excel General
    Replies: 3
    Last Post: 11-10-2005, 11:45 PM

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