InStr Function

fluxcapacitr609

New Member
Joined
Feb 21, 2018
Messages
24
Code:
Dim LastRow As LongDim erow As Long
Dim i As Long
Dim strComp


LastRow = Sheet2.Cells(Rows.Count, 1).End(xlUp).Row
Sheet2.Select
Range("A1").Select


For i = 2 To LastRow


    
    strComp = Cells(i, 3)
    If InStr(1,strComp,"Fuel Consumed")= 1 Then
    erow = Sheet4.Cells(Rows.Count, 9).End(xlUp).Offset(1, 0).Row
    Range(Cells(i, 1), Cells(i, 4)).Copy Destination:=Sheet4.Range("I" & erow)
    End If



Im trying to search a column for a rows with the phrase "Fuel Consumed" in it then paste the rows with matching criteria in it into another sheet. I have a version of this that uses a date range and works.

Im getting an Sytax error at the "If" line.
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
I unfortunately cant do it that way. Im actually going to be combining it with other code to make it a nested loop with data being distributed throughout the workbook. Im just trying to get the syntax of the InStr Function correct.
 
Upvote 0
StrComp is a function, which is why you are getting the problem.
Change the name of your variable
 
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