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

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.

Forum statistics

Threads
1,215,528
Messages
6,125,342
Members
449,218
Latest member
Excel Master

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