Macro to Copy Certain Columns to another worksheet based on cell value

Miroy72

New Member
Joined
Aug 7, 2014
Messages
47
I m trying to write a code that will look in worksheet "Sox Controls 2018" for a value "Nov1" in Column C (The heading in column starts in C3) and copy over data that's in columns D, F, H, J, P, Q, R, I to a new worksheet that is called "Nov" starting in cell A2.

Here is what have so far which copies the whole row but I only want the rows that I mentioned above. And I want the data to start in A2 in "Nov" worksheet.

Code:
 Sub November2()
    Dim xRg As Range
    Dim xCell As Range
    Dim I As Long
    Dim J As Long
    Dim K As Long
    I = Worksheets("SOX Controls 2018").UsedRange.Rows.Count
    J = Worksheets("Nov").UsedRange.Rows.Count
    If J = 1 Then
    If Application.WorksheetFunction.CountA(Worksheets("Nov").UsedRange) = 0 Then J = 0
    End If
    Set xRg = Worksheets("SOX Controls 2018").Range("C3:C" & I)
    On Error Resume Next
    Application.ScreenUpdating = False
    For K = 1 To xRg.Count
        If CStr(xRg(K).Value) = "Nov1" Then
            xRg(K).EntireRow.Copy Destination:=Worksheets("Nov").Range("A" & J + 1)
            J = J + 1
        End If
    Next
    Application.ScreenUpdating = True
End Sub

Thanks so much!
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.

Forum statistics

Threads
1,215,028
Messages
6,122,753
Members
449,094
Latest member
dsharae57

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