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:

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Hi,

This is working to select and copy/paste the range, but i'm not sure what to do about the dropdown.

Hope you can adjust to suit your needs.

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(7).Cells(rownum, 1) = ""
If Sheets(7).Cells(rownum, 1) = findcolA And Sheets(7).Cells(rownum, 3) = findcolC Then
Startrow = rownum
GoTo FindLastRow
End If
rownum = rownum + 1
Loop




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




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


End Sub
 
Last edited:
Upvote 0
Thanks marshl9898

I will give it a try and let you know how I get on

many thanks,

much appreciated :)

pwill
 
Upvote 0
Hi,

This is working to select and copy/paste the range, but i'm not sure what to do about the dropdown.

Hope you can adjust to suit your needs.

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(7).Cells(rownum, 1) = ""
If Sheets(7).Cells(rownum, 1) = findcolA And Sheets(7).Cells(rownum, 3) = findcolC Then
Startrow = rownum
GoTo FindLastRow
End If
rownum = rownum + 1
Loop




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




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


End Sub

Hi marshl9898, I just tried your code but it errors I get 'run time error 1004' Application-defined orbject-defined error

and nothing gets copied to sheet3?

Am I doing something wrong? should I have said there are many more rows than I gave in the example, the Names run 0 1 -1 and there is hundreds of rows for each name and Ref

Reagards

pwill
 
Last edited:
Upvote 0
Which version of excel are you running?

You don't have option explicit above the code do you?

Click debug and let me know which line it stops on please.

It won't matter how many rows there are.
 
Upvote 0
Hi,

No I'm not using Option explicit but I wasn't using a module, I just tried it with a module and it debugs at the line

Sheets(3).Range("A3").PasteSpecial xlPasteValues

regards

pwill
 
Upvote 0
Try

Code:
[COLOR=#333333]Sheets(3).select[/COLOR]
[COLOR=#333333]Range("A3").PasteSpecial xlPasteValues
[/COLOR]
 
Upvote 0
Hi,

It still Debugs with

Range("A3").PasteSpecial xlPasteValues

Its trying, but just seems to select A3 on Sheet3 and stops?

regards
 
Upvote 0

Forum statistics

Threads
1,215,528
Messages
6,125,342
Members
449,218
Latest member
Excel Master

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