• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 723
  • Last Modified:

sort excel table and copy visible cells invba

Hi experts
I'm trying to sort an excel table in vba , and then copy the visible cells only to a different table on a different sheet any ideas how I can do this in vba ?

cheers
0
Thrawn3000
Asked:
Thrawn3000
  • 2
  • 2
1 Solution
 
StephenJRCommented:
Can you post a workbook?
0
 
Thrawn3000Author Commented:
Yes sure
I want to filter the table in vba for all AAMI values under the brand field and then a specific date as an example and copy these visible cells to a different table. TestFile.xlsx
0
 
StephenJRCommented:
Like this? Not sure what you meant by sorting, did you just mean filtering?
Sub x()

Dim rData As Range

Application.ScreenUpdating = False

With Sheets("Sheet1")
    .AutoFilterMode = False
    .Range("A1").AutoFilter Field:=1, Criteria1:=DateSerial(2010, 7, 31)
    With .AutoFilter.Range
        On Error Resume Next
        Set rData = .Offset(1).Resize(.Rows.Count - 1).SpecialCells(xlCellTypeVisible)
        On Error GoTo 0
        If Not rData Is Nothing Then
            rData.Copy Sheets("Sheet2").Range("A1")
        End If
    End With
    .AutoFilterMode = False
End With

Application.ScreenUpdating = True

End Sub

Open in new window

0
 
Thrawn3000Author Commented:
Awesom, works perfectly
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now