Trouble with a searching macro

katralic

New Member
Joined
Mar 16, 2023
Messages
6
Office Version
  1. 2010
Platform
  1. Windows
I'm trying to do a simple search macro that displays results but keep getting an error on 1 line of the code.

Sub search()
'declare variables
Dim name As String
Dim finalrow As Integer
'r meaning row
Dim r As Integer
'clear old search results
Range("k21:w30").ClearContents
'Sets the customers name that was entered into k20 as Name
name = Sheets("Customer Search").Range("k20").Value
' Customer list starts in column G
'sets the final row to stop searching
finalrow = Sheets("customer info").Range("g2").End(x1down).row
'searches from row 2 to final row
For r = 2 To finalrow
'if the row it's in, column 7 (which would be g)lists the name then it copies and pastes that row from column g to column s.
If Cells(r, 7) = name Then
Sheets("customer info").Range(Cells(r, 7), Cells(r, 19)).Copy
Sheets("Customer Search").Range("k50").End(x1up).Offset(1, 0).rowPasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
Application.ScreenUpdating = False
End If
Next r


End Sub

I keep getting an error on
finalrow = Sheets("customer info").Range("g2").End(x1down).row
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
What is the error number and error message you get?
 
Upvote 0
I'm trying to do a simple search macro that displays results but keep getting an error on 1 line of the code.

Sub search()
'declare variables
Dim name As String
Dim finalrow As Integer
'r meaning row
Dim r As Integer
'clear old search results
Range("k21:w30").ClearContents
'Sets the customers name that was entered into k20 as Name
name = Sheets("Customer Search").Range("k20").Value
' Customer list starts in column G
'sets the final row to stop searching
finalrow = Sheets("customer info").Range("g2").End(x1down).row
'searches from row 2 to final row
For r = 2 To finalrow
'if the row it's in, column 7 (which would be g)lists the name then it copies and pastes that row from column g to column s.
If Cells(r, 7) = name Then
Sheets("customer info").Range(Cells(r, 7), Cells(r, 19)).Copy
Sheets("Customer Search").Range("k50").End(x1up).Offset(1, 0).rowPasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
Application.ScreenUpdating = False
End If
Next r


End Sub

I keep getting an error on
finalrow = Sheets("customer info").Range("g2").End(x1down).row
Update. I figured it out. instead of x1down it should be lxdown. Mmy font was set so the 1 and l looked the same.
 
Upvote 0

Forum statistics

Threads
1,223,711
Messages
6,174,029
Members
452,542
Latest member
Bricklin

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