vba to find a cell containing a value then select a specific range below it

cjcass

Well-known Member
Joined
Oct 27, 2011
Messages
683
Office Version
  1. 2016
Platform
  1. Windows
Hi,
I'm looking for a macro that will look at the value (text) in cell A1 of Sheet1 then go to Sheet2 and search for the same value (it will be unique) in Row 4 of Sheet2 and then when it finds the location in Row 4 select the column which is one column to the right and rows 10:200 of that column.
Example: Sheet1 A1 contains the word 'London', it searches row 4 in Sheet2 for 'London', finds it at BS4 and then selects the range BT10:BT200.
Hope this makes sense?
Thanks
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Can you tell us what you are going to do with the range once selected?
I ask because it is rare that you need to actually select a range to work with it and selecting slows your code.
 
Upvote 0
Hi,
I'm going to copy it and paste it into another sheet
 
Upvote 0
Hi,
I'm going to copy it and paste it into another sheet
OK, you didn't tell us what sheet is to get copied to or what range on that sheet so you will have to modify the blue part of this code but hopefully this gets you close (without selecting that range. :))

Rich (BB code):
Sub FindAndCopyRange()
  Dim rFound As Range
  
  Set rFound = Sheets("Sheet2").Rows(4).Find(What:=Sheets("Sheet1").Range("A1").Value, LookIn:=xlValues, LookAt:=xlWhole, MatchCase:=False)
  If Not rFound Is Nothing Then rFound.Offset(6, 1).Resize(191).Copy Destination:=Sheets("Sheet3").Range("B8")
End Sub
 
Last edited:
Upvote 0
That's great, just one final bit, I'd like to copy just the values if poss. how would I adjust the code to suit this?
Thanks.
 
Upvote 0
I'd like to copy just the values if poss.
try
Code:
Sub FindAndCopyRange()
  Dim rFound As Range
  
  Set rFound = Sheets("Sheet2").Rows(4).Find(What:=Sheets("Sheet1").Range("A1").Value, LookIn:=xlValues, LookAt:=xlWhole, MatchCase:=False)
  If Not rFound Is Nothing Then
    rFound.Offset(6, 1).Resize(191).Copy
    Sheets("Sheet3").Range("B8").PasteSpecial xlValues
    Application.CutCopyMode = False
  End If
End Sub
 
Upvote 0
Hello

I am seeking a similar problem to the above, but with a twist.
I have a large Excel data base of bacteria Genus' and i need to match the name in one worksheet, to another worksheet, copy that whole row (or a selection, say 4 columns), and paste into another worksheet.
Example... I have 3 worksheets A, B, C

Worksheet A has 1000's of rows of names and many columns of data to each row name, but the name is always in Column A and will be alphabetical.

Worksheet B has the pasted names in Column A (also alphabetical) im looking to match with in Worksheet A, column A.
Worksheet C, is for pasting, or can be pasted into B, but for now easier into worksheet C.

So... open worksheet B, cell A1.. that word there "ABAB", use this cell as the search term to search in worksheet A, cell A1... if a match... copy all of worksheet A Row 1, and paste into worksheet C Row 1.

Repeat, open worksheet B, cell A2... that word there, "GHGH, use this cell as the search term to search in worksheet A, cell A2 = negative, cell A3 = negative, cell A4 match. Copy entire row A4, paste into worksheet C row 2..... Continue until blank empty cell in worksheet B, Column A.... this can be hundreds to 1000's of rows long.

So the search word / term will be different for each search, and terms shouldnt be repeated, cause it will be alphabetical.
This is my problem, and I am currently doing this manually.. term by term.
 
Upvote 0
Hello

I am seeking a similar problem to the above, but with a twist.
I have a large Excel data base of bacteria Genus' and i need to match the name in one worksheet, to another worksheet, copy that whole row (or a selection, say 4 columns), and paste into another worksheet.
Example... I have 3 worksheets A, B, C

Worksheet A has 1000's of rows of names and many columns of data to each row name, but the name is always in Column A and will be alphabetical.

Worksheet B has the pasted names in Column A (also alphabetical) im looking to match with in Worksheet A, column A.
Worksheet C, is for pasting, or can be pasted into B, but for now easier into worksheet C.

So... open worksheet B, cell A1.. that word there "ABAB", use this cell as the search term to search in worksheet A, cell A1... if a match... copy all of worksheet A Row 1, and paste into worksheet C Row 1.

Repeat, open worksheet B, cell A2... that word there, "GHGH, use this cell as the search term to search in worksheet A, cell A2 = negative, cell A3 = negative, cell A4 match. Copy entire row A4, paste into worksheet C row 2..... Continue until blank empty cell in worksheet B, Column A.... this can be hundreds to 1000's of rows long.

So the search word / term will be different for each search, and terms shouldnt be repeated, cause it will be alphabetical.
This is my problem, and I am currently doing this manually.. term by term.
You should post your question to a new thread of its own, instead of posting to a thread that is 7 years old.
That way, it will appear as a new question on the "Unanswered threads" listing that many people use to look for new questions to help out on.
You can include a link back to this thread if you think that would be helpful to your question.
 
Upvote 0

Forum statistics

Threads
1,224,828
Messages
6,181,209
Members
453,022
Latest member
RobertV1609

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