Find part of 'Text' then copy that row and one above to worksheet

leeksleeks

Board Regular
Joined
Oct 31, 2013
Messages
96
Hi,

I have been looking for some code to find a row within "Sheet1" containing a word with a question mark next to it and then copy that row and the row above to the next worksheet "Sheet2". I have tried other peoples codes but they dont incorporate finding part of a word. Below is the code I have been trying but I cannot get this to find the questionmark attached to the word. Also this code doesnt copy the row above either. Any help with this would be greatly appreciated.


Code:
Sub CopyRows()    Dim bottomL As Integer
    bottomL = Sheets("Sheet1").Range("L" & Rows.Count).End(xlUp).Row
     
    Dim c As Range
    For Each c In Sheets("Sheet1").Range("A1:Z170" & bottomL)
        If c.Value = "*?" Then
            c.EntireRow.Copy Worksheets("Sheet2").Range("A" & Rows.Count).End(xlUp).Offset(1)
        End If
    Next c
     
End Sub
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
I have been looking for some code to find a row within "Sheet1" containing a word with a question mark next to it and then copy that row and the row above to the next worksheet "Sheet2". I have tried other peoples codes but they dont incorporate finding part of a word. Below is the code I have been trying but I cannot get this to find the questionmark attached to the word. Also this code doesnt copy the row above either. Any help with this would be greatly appreciated.
Code:
Sub CopyRows()    Dim bottomL As Integer
    bottomL = Sheets("Sheet1").Range("L" & Rows.Count).End(xlUp).Row
     
    Dim c As Range
    For Each c In Sheets("Sheet1").Range[COLOR=#000000]([/COLOR][COLOR=#FF0000][B]"A1:Z170" & bottomL[/B][/COLOR])
        If c.Value = "*?" Then
            c.EntireRow.Copy Worksheets("Sheet2").Range("A" & Rows.Count).End(xlUp).Offset(1)
        End If
    Next c  
End Sub
First off, I think the part I highlighted in red is incorrect... I cannot believe you want to concatenate those values, rather, I think you want the bottomL to be lowest row of the range so that is what I used below. With that said, I think this code will do what you want...
Code:
Sub CopyRows()
  Dim bottomL As Integer
  bottomL = Sheets("Sheet1").Range("L" & Rows.Count).End(xlUp).Row
   
  Dim c As Range
  For Each c In Sheets("Sheet1").Range("A1:Z" & bottomL)
    If c.Value Like "*[A-Za-z][?]*" Then
      c.Offset(-1).Resize(2).EntireRow.Copy Worksheets("Sheet2").Range("A" & Rows.Count).End(xlUp).Offset(1)
    End If
  Next c
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,179
Messages
6,123,495
Members
449,100
Latest member
sktz

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