Copy Columns but not certain Rows

OO7Goofy

New Member
Joined
Jul 10, 2018
Messages
13
Hey All! I'm new to excel vba and I'm attempting to generate a report from downloaded data. The data usually includes some extra columns that are unnecessary along with rows if a certain box is marked "x". I'm attempting to copy all columns with certain headers but exclude those rows that have an "x" in a specific column. Below is what I have so far.
Code:
Private Sub Run_Click()
Dim wsO As Worksheet
Dim wsF As Worksheet
Dim i As Integer

 Application.ScreenUpdating = False
Set wsO = Worksheets("Data")
Set wsF = Worksheets("Output")
 myColumns = Array("A", "C", "E", "F", "G", "J")
With wsO.Range("A1:W1")
For i = 0 To UBound(myColumns)
On Error Resume Next
 .Find(myColumns(i)).EntireColumn.Copy Destination:=wsF.Cells(1, i + 1)
 Err.Clear
Next i
End With
Set wsO = Nothing
Set wsF = Nothing
 Application.ScreenUpdating = True
End Sub

My Goal is to exclude rows where column B row "x" has a "X" in the box. Any help would be greatly appreciated!
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
Hi & welcome to MrExcel.
How about
Code:
Private Sub Run_Click()
   Dim wsO As Worksheet
   Dim wsF As Worksheet
   Dim i As Integer
   Dim MyColumns As Variant
   Dim Fnd As Range
   
   Application.ScreenUpdating = False
   Set wsO = Worksheets("Data")
   Set wsF = Worksheets("Output")
   MyColumns = Array("A", "C", "E", "F", "G", "J")
   
   With wsO.Range("A1:W1")
      If wsO.AutoFilterMode Then wsO.AutoFilterMode = False
      .AutoFilter 2, "<>x"
      For i = 0 To UBound(MyColumns)
         Set Fnd = .find(MyColumns(i))
         If Not Fnd Is Nothing Then
            Intersect(Fnd.EntireColumn, wsO.AutoFilter.Range).Copy Destination:=wsF.Cells(1, i + 1)
         End If
      Next i
   End With
   Set wsO = Nothing
   Set wsF = Nothing
   Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,751
Messages
6,126,669
Members
449,326
Latest member
asp123

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top