Results 1 to 4 of 4

Macro copying Column Range instead of individual Column

Threaded View

  1. #1
    Registered User
    Join Date
    09-20-2017
    Location
    Vancouver
    MS-Off Ver
    2013
    Posts
    4

    Macro copying Column Range instead of individual Column

    I've written a basic macro with extracts records based on two dates:

    Sub extractDataBasedOnDate()
    
    Dim lastrow As Long, erow As Long, i As Long
    Dim mydate As Date
    Dim StartDate As Date
    Dim EndDate As Date
    
    StartDate = Worksheets("Expense Report").Cells(3, 1).Value
    EndDate = Worksheets("Expense Report").Cells(3, 2).Value
    lastrow = Worksheets("Expenses").Cells(Rows.Count, 1).End(xlUp).Row
    
    Worksheets("Expense Report").Rows(7 & ":" & Sheet2.Rows.Count).Delete
    
    Worksheets("Expenses").Activate
    Worksheets("Expenses").Range("A1").Select
    
    For i = 2 To lastrow
    
        mydate = Cells(i, 6)
        If mydate >= StartDate And mydate <= EndDate Then
        erow = Sheet2.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
        Range(Cells(i, 2), Cells(i, 6)).Copy Destination:=Sheets("Expense Report").Cells(erow, 1)
        End If
    Next i
    
    End Sub
    The problem I am having is that it is returning every column between Cells(i, 2) to Cells(i , 6).
    I had intended to only copy the two columns (Column B and F), how can I achieve this?
    Do I need to do a separate line for each column?

    Thanks!
    Last edited by GuardianEnzo; 09-20-2017 at 07:17 PM.

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: 11-05-2015, 11:58 AM
  2. [SOLVED] Column Range copying and pasting to another column
    By vtcin in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-26-2014, 07:06 PM
  3. Replies: 2
    Last Post: 04-11-2014, 12:18 PM
  4. Replies: 2
    Last Post: 10-30-2013, 06:03 PM
  5. [SOLVED] Excel 2007 Column Chart - change individual column colour
    By SAsplin in forum Excel Charting & Pivots
    Replies: 2
    Last Post: 10-25-2013, 06:57 AM
  6. Replies: 3
    Last Post: 05-10-2013, 04:07 AM
  7. macro for copying a range to a column of cells
    By [email protected] in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-08-2006, 08:15 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