Consulting

Results 1 to 6 of 6

Thread: Copy a column from one tab to another using a column reference

  1. #1

    Copy a column from one tab to another using a column reference

    Hi. I would like to copy a column using the column name instead of a column reference. With reference to the code below, I would like to change the Autofilter field:=70 to a autofilter:= (to the name of the column) i.e date/time etc. And I would like to change the range command to include the name of the column instead of the BR10 or so. ThanksSheets("Overall - Basestock Lifting").Activate Range("BR10").Select Selection.AutoFilter Field:=70, Criteria1:="1" Range("BU10").Select Selection.AutoFilter Field:=73, Criteria1:="TRUE" Range(Cells(14, 2), Cells(i, 3)).Select Selection.Copy Sheets("Gp I Lifting").Select Range("A5").Select Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _ :=False, Transpose:=False

  2. #2
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,876
    Could you attach a version of your workbook with this?
    It's hard work to reproduce your scenario.
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  3. #3

    Copy a column from one tab to another using a column reference

    I would like to copy a column data with the header "date" from a worksheet name "Grades" and then copy into another column "Date" in another worksheet named "results". Both of these worksheets is in a same workbook. Is there a generic code to execute this? thanks.

  4. #4
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,876
    Quote Originally Posted by p45cal View Post
    Could you attach a version of your workbook with this?
    I'll take that as a no then.
    try:
    Sub blah()
    With Sheets("Grades")
      SourceColumn = Application.Match("Date", .Rows(1), 0)
      Set SourceRange = Intersect(.UsedRange, .Columns(SourceColumn)).Offset(1)
    End With
    With Sheets("Results")
      DestinationColumn = Application.Match("Date", .Rows(1), 0)
      Set DestinationRange = .Cells(2, DestinationColumn) 'or if there's already something there:
      'Set DestinationRange = .Cells(.Rows.Count, DestinationColumn).End(xlUp).Offset(1)
    End With
    SourceRange.Copy DestinationRange
    End Sub
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  5. #5

    Copy a column from one tab to another using a column reference

    Hi. Thanks a lot,p45cal. It works. However, how do i edit the code, if the column range that I want to select does not start from row 1 instead? And i just want to select the data downwards? For example, I want to copy the column data with the column name "date" but not including the "date", just the data in the following rows? Appreciate your help.

  6. #6
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,064
    Location
    Change the value in
    SourceColumn = Application.Match("Date", .Rows(1), 0)
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •