I am trying to write a macro that copies a row if a cell in that row contains text (For ex: Mumbai, Delhi etc) from Column C.
For example if there are 30 rows but only 15 contains text(Mumbai & Delhi) in column C. I want to copy those 15 rows and paste them into "Sheet2" I was using the below code. however it is copying all the filled rows. however my requirement is the code should only need to copy columns of a, b, c, d, f, g, h, i, l & m to Sheet2.
Sub testPasteinSh2() Dim sh1 As Worksheet, sh2 As Worksheet, rng As Range, cel As Range Dim rngCopy As Range, lastR1 As Long, lastR2 As Long Dim strSearch1 As String, strSearch2 As String strSearch1 = "Mumbai" 'or combo value... strSearch2 = "Delhi" 'or something else... Set sh1 = ActiveSheet 'use here your worksheet Set sh2 = Worksheets("Sheet2") 'use here your sheet lastR1 = sh1.Range("C" & Rows.count).End(xlUp).Row lastR2 = sh2.Range("A" & Rows.count).End(xlUp).Row + 1 Set rng = sh1.Range("C2:C" & lastR1) For Each cel In rng.cells If cel.Value = strSearch1 Or cel.Value = strSearch2 Then If rngCopy Is Nothing Then Set rngCopy = sh1.Rows(cel.Row) Else Set rngCopy = Union(rngCopy, sh1.Rows(cel.Row)) End If End If Next If Not rngCopy Is Nothing Then rngCopy.Copy Destination:=sh2.cells(lastR2, 1) End If End Sub Can you please help me. Thank you in Advance.
