Results 1 to 2 of 2

Macro to copy certain columns and paste in new sheet

Threaded View

  1. #1
    Forum Contributor
    Join Date
    03-30-2007
    Location
    London, UK
    MS-Off Ver
    Microsoft Office 2007
    Posts
    317

    Smile Macro to copy certain columns and paste in new sheet

    Hi

    I wonder if someone can help me, I need some code to help me copy the ranges in certain columns and paste them into a new worksheet. I have raw data on my "Data" worksheet but I need to export this into a word doc as the fields on the source data sheet are all over the place.

    This is what I have so far to create the new sheet:
    Sub CopyData()
    
        Dim WS As Worksheet
        Set WS = Sheets.Add
        WS.Name = "Export_Data"
        
        Sheets("Data_Source").Select
        Range("M1").Select
        Range(Selection, Selection.End(xlUp)).Select
        Selection.Copy
        
        Sheets("Export_Data").Select
        Range("A1").Select
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
            :=False, Transpose:=False
    
        Sheets("Data_Source").Select
        Range("I1").Select
        Range(Selection, Selection.End(xlUp)).Select
        Selection.Copy
        
        Sheets("Export_Data").Select
        Range("B1").Select
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
            :=False, Transpose:=False
            
         Sheets("Data_Source").Select
        Range("J1").Select
        Range(Selection, Selection.End(xlUp)).Select
        Selection.Copy
        
        Sheets("Export_Data").Select
        Range("C1").Select
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
            :=False, Transpose:=False
        
        Sheets("Data_Source").Select
        Range("K1").Select
        Range(Selection, Selection.End(xlUp)).Select
        Selection.Copy
        
        Sheets("Export_Data").Select
        Range("D1").Select
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
            :=False, Transpose:=False
    End Sub
    Now that the "Export Data" sheet has been created I wanted a macro that would copy the values from the following ranges/sheets:

                Data source       Export Data
    Column            M      to         A
                      I      to         B
                      J      to         C
                      K      to         D
    This isn't probably the most efficient use of code but my VBA skills are limited. The trouble I have is some of the cells are blank so I would need to select from row 1 then filter up from row 65536 that that the whole range in the column would be selected.

    This would also make the importing of the necessary data much easier for me as some of it has to be inputted manually.

    Any help would be gratefully received.

    Thanks.
    Last edited by Zyphon; 03-10-2009 at 04:51 AM. Reason: Managed to solve the problem myself. :)
    Best Regards.

    Michael
    -----------------------------------
    Windows Vista, Microsoft Office 2007

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