Find and Select Rows

pwill

Active Member
Joined
Nov 22, 2015
Messages
406
Hi can anyone help with a macro that I could use with a drop down list that will find and select rows based on Name from column A and the Ref from column C (Sheet7)

IE if I wanted to find 1 as the name from column A and 10 as the Ref in column C in this example A14:J16 would be selected or if I wanted to find 0 as the Name and 15 as the Ref A8:J10 would be selected and so on... and then copy the selected range to Sheet3 A3:J


ABCDEFGHIJKLM
1NameRangeRefABCDEFG


201 - 550000000


306 - 1051111111


4011 - 1552222222


501 - 10103333333


6011 - 20104444444


7021 - 30105555555


801 - 15156666666


9016 - 30157777777


10031 - 45158888888


1111 - 550000000


1216 - 1051111111


13111 - 1552222222


1411 - 10103333333


15111 - 20104444444


16121 - 30105555555


1711 - 15156666666


18116 - 30157777777


19131 - 45158888888


20












21













<tbody>
</tbody>

Any help would be appreciated

Regards

pwill
 
Last edited:
Hi,

Its saying you can't paste here because the copy area and paste area arn't the same size?
 
Upvote 0

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Yes it goes to sheet3 but then stops with the debug message

I've just reopened my workbook and going to try again from scratch
 
Upvote 0
Hi mrshl9898

just tried again but it just keeps stopping at sheet3 it selects cell A3

regards
 
Upvote 0
Hi could it be that I have the same Ref value for other names and its trying to select the too?
 
Upvote 0
ok thanks :)

with the drop down I was thinking I could use one column for the name say K1 and L1 for the Ref? but I will try that another day lol
 
Upvote 0
Try this, for some reason using the index number makes cells(2,1) = "".....

That gave me the error you see with the print area.

Naming the sheets fixed it on my end.

(I must point out I don't usually use index numbers so am a bit unfamiliar with the ins and outs.)

Code:
Sub selectrows()



Dim findcolA As Long
Dim findcolC As Long




findcolA = InputBox("Enter Value for Column A")
findcolC = InputBox("Enter Value for Column C")




rownum = 2
Do Until Sheets("PrdRes").Cells(rownum, 1).Value = ""
If Sheets("PrdRes").Cells(rownum, 1) = findcolA And Sheets("PrdRes").Cells(rownum, 3) = findcolC Then
Startrow = rownum
GoTo FindLastRow
End If
rownum = rownum + 1
Loop








FindLastRow:
Do Until Sheets("PrdRes").Cells(rownum, 1) = ""
If Sheets("PrdRes").Cells(rownum, 1) = findcolA And Sheets("PrdRes").Cells(rownum, 3) = findcolC Then
Lastrow = rownum
End If
rownum = rownum + 1
Loop








Let Copyrange = "A" & Startrow & ":" & "J" & Lastrow
Sheets("PrdRes").Range(Copyrange).Copy
Sheets("Data").Range("A3").PasteSpecial xlPasteValues




End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,216,577
Messages
6,131,511
Members
449,653
Latest member
andz

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