gpt-3.5-turbo-0301· OpenAI
WildChat-4.8M (AI2)
Please write me a Microsoft Excel VBA script. The script needs to filter the column…
- User
Please write me a Microsoft Excel VBA script. The script needs to filter the column "issues" which contain the word "yes" from the Table "Table2". The filtered results then need to be pasted into a new worksheet. The script needs to also filter the column "issues" which contain the word "yes" from the Table "Table1". The filtered results then need to be pasted into a new worksheet.
- Assistant
Sub FilterAndCopy() Dim tbl2 As ListObject Dim tbl2Col As Range Dim tbl2Filtered As Variant Dim tbl2Count As Long
codeSet tbl2 = Worksheets("Sheet1").ListObjects("Table2") Set tbl2Col = tbl2.ListColumns("Issues").DataBodyRange tbl2Col.AutoFilter Field:=1, Criteria1:="yes" tbl2Filtered = tbl2.DataBodyRange.SpecialCells(xlCellTypeVisible).Value tbl2Count = UBound(tbl2Filtered, 1) If tbl2Count > 0 Then Worksheets.Add.Name = "Table2 Filtered" Range("A1").Resize(tbl2Count, tbl2.ListColumns.Count).Value = tbl2Filtered End If tbl2Col.AutoFilter Dim tbl1 As ListObject Dim tbl1Col As Range Dim tbl1Filtered As Variant Dim tbl1Count As Long Set tbl1 = Worksheets("Sheet1").ListObjects("Table1") Set tbl1Col = tbl1.ListColumns("Issues").DataBodyRange tbl1Col.AutoFilter Field:=1, Criteria1:="yes" tbl1Filtered = tbl1.DataBodyRange.SpecialCells(xlCellTypeVisible).Value tbl1Count = UBound(tbl1Filtered, 1) If tbl1Count > 0 Then Worksheets.Add.Name = "Table1 Filtered" Range("A1").Resize(tbl1Count, tbl1.ListColumns.Count).Value = tbl1Filtered End If tbl1Col.AutoFilter