Find Text Within A Row, Then Copy Information Below That Cell To Second Worksheet

kstoneman

New Member
Joined
Feb 7, 2014
Messages
2
I’ve recently taken over an Excel workbook that uses VBA to find, copy, and paste information between two workbooks. I’m relatively new to Excel VBA coding, so I’m looking for any help that will reduce the vast number of lines, over 300, of redundant coding. I will be unable to provide the actual coding as it includes sensitive information and would take a lot of time to make the coding genetic. Here is what I want to accomplish:

  • Find each instance of text within a row range
  • Once I find a cell with text, I want to copy the cell and a 5x5 block of information, which is two rows below that cell, to another workbook
  • The copied information needs to be appended to the last used row in the second worksheet


I’ve searched the web for ideas on how to accomplish this. I can find snippets of coding that can do some parts, but I don’t know how to consolidate and organize the coding into a single process.

The attached file is a very raw example of the type of data I’m using. The three blocks of values on the source tab need to be pasted into the destination worksheet. Currently, in the destination tab is the format/result required.

Any help is greatly appreciated.

Example 1.xlsx
ABCDEFGHIJKLMNOPQR
1
2typeCSS1B
31451531411128213219129234175
414018416612740122511153396264
500000106841105874182
6777270119234181698113134
74210393129226220125204143
Source




Example 1.xlsx
ABCDEF
3typeval1val2val3val4val5
4C1451531411
5C140184166
6C00000
7C777270
8C4210393
9SS128213219
10SS12740122511
11SS10684110
12SS1192341816
13SS129226220
141B129234175
151B153396264
161B5874182
171B98113134
181B125204143
Destination
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
I suggest that you update your Account details (or click your user name at the top right of the forum) so helpers always know what Excel version(s) & platform(s) you are using as the best solution often varies by version. (Don’t forget to scroll down & ‘Save’)

Based on the sample data layout above and assuming ...
  1. Headers exist already in 'Destination' (though code could add them if required)
  2. Values in 'Source' row 3 are constants (that is, not the result of formulas)
.. give this a try with a copy of your workbook.

VBA Code:
Sub Copy_Blocks()
  Dim rA As Range

  For Each rA In Sheets("Source").Rows(3).SpecialCells(xlConstants).Areas
    rA.Resize(5).Copy Destination:=Sheets("Destination").Range("B" & Rows.Count).End(xlUp).Offset(1)
    Sheets("Destination").Range("A" & Rows.Count).End(xlUp).Offset(1).Resize(5).Value = rA.Cells(0, 1).Value
  Next rA
End Sub
 
Upvote 0
Cross-posting (posting the same question in more than one forum) is not against our rules, but the method of doing so is covered by #13 of the Forum Rules.

Be sure to follow & read the link at the end of the rule too!

Cross posted at: Find Text Within A Row, Then Copy Information Below That Cell To Second Worksheet
and Find Text Within A Row, Then Copy Information Below That Cell To Second Worksheet
and Find Text Within A Row, Then Copy Information Below That Cell To Second Worksheet

If you have posted the question at more places, please provide links to those as well.

If you do cross-post in the future and also provide links, then there shouldn’t be a problem.
 
Upvote 0

Forum statistics

Threads
1,215,137
Messages
6,123,254
Members
449,093
Latest member
Vincent Khandagale

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