VBA code to copy range of cells in row based on criteria

ryanw1

New Member
Joined
Mar 11, 2019
Messages
7
Good Evening,

I have been searching for some time now for examples online and similar post for what I need with no success. I am here now to ask for assistance.

I need a VBA code that will be run by a command button to copy a specific range of cells in a specific row and paste the cells to a different sheet. This would only be based on if any cells in column D contains "ECS" and are not hidden. Example: D12, D15, D17 are not hidden and contain "ECS". Cell ranges B12:I12, B15:I15, and B17:I17 are all copied and pasted to sheet 2 starting at Cell B2.

All help will be greatly appreciated.
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
The order form sheet is names ECS Testing Scope.

The range to be cleared is B8 - F30

Thanks for you help.
You'll have to integrate this with your code for different source sheets or post that code and ask for some help. The code below asssumes the source sheet is active when the code is executed.
Code:
Sub CopyIfECS2()
Dim R As Range, c As Range, NxRw As Long, OrderSht As Worksheet
Set OrderSht = Sheets("ECS Testing Scope")
OrderSht.Range("B8:F30").ClearContents
Set R = Range("D1:D" & Cells(Rows.Count, "D").End(xlUp).Row)
For Each c In R
    If c.Value = "ECS" Then
        If c.EntireRow.Hidden = False Then
            NxRw = OrderSht.Cells(OrderSht.Rows.Count, "B").End(xlUp).Row + 1
            Range(Cells(c.Row, "B"), Cells(c.Row, "I")).Copy Destination:=OrderSht.Range("B" & NxRw)
        End If
    End If
Next c
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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