+ Reply to Thread
Results 1 to 2 of 2

select only certain columns depending upon last row in column A

  1. #1
    Registered User
    Join Date
    06-08-2011
    Location
    Worcester
    MS-Off Ver
    Excel 2003
    Posts
    10

    Post select only certain columns depending upon last row in column A

    I have the following code, which works fine when selecting ALL the columns A:F

    How can I change this so that it only selects Columns A and F and copies the values to the destination range?


    Private Sub CommandButton1_Click()
    'collate data from all daily sheets onto Week sheet
    Dim firstRow As Double, lastRow As Double, srcRng As Range, destRng As Range, ws As Worksheet
    firstRow = 6
    For Each ws In Sheets
    'goes through the workbook grabbing data, if the sheet isn't called "Graphs" or "Week"
    With ws
    If (.Name) <> "Graphs" And (.Name) <> "Week" Then
    'finds last used row by selecting last row and simulating ctrl-up arrow
    lastRow = .Cells(Rows.Count, "A").End(xlUp).Row
    If lastRow >= firstRow Then 'makes sure there's some data to copy
    'gets range of data in current sheet
    Set srcRng = .Range(.Cells(firstRow, "A"), .Cells(lastRow, "F"))
    'gets range of first cell on row below data already on sheet
    Set destRng = Sheets("Week").Cells(Rows.Count, "B").End(xlUp).Resize(lastRow - firstRow + 1, 6).Offset(1, -1)
    destRng.Value = srcRng.Value
    End If
    End If

    End With
    Next ws

  2. #2
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: select only certain columns depending upon last row in column A

    Please use code tags

    This line is setting range A up to F
    Please Login or Register  to view this content.
    And you just want Columns A and F only
    Please Login or Register  to view this content.
    But the destination range is not clear

+ Reply to Thread

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