Search Range of Cells, Copy Cell Value in adjacent cells if criteria is me

SensualCarrots

New Member
Joined
Mar 21, 2015
Messages
46
I've been searching for this for a while. I've only found hybrids of what I'm trying to do. It seems simple enough, but I just can't get it to work.

[TABLE="width: 500"]
<tbody>[TR]
[TD]A[/TD]
[TD]A.1[/TD]
[/TR]
[TR]
[TD]A.1[/TD]
[TD]B.1[/TD]
[/TR]
[TR]
[TD]B[/TD]
[TD]B.2[/TD]
[/TR]
[TR]
[TD]B.1[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]B.2[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]C[/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]

Basically, a macro that will search a range of cells for a particular character or string of characters, and copy the entire cell value if it finds it. Any thoughs?
 
This will do cols A:N
Code:
Sub GetValus()
   Dim Ary As Variant
   Dim Nary() As Variant
   Dim i As Long, j As Long, k As Long
   Ary = Application.Transpose(Sheets("Sheet1").Range("A1", Sheets("Sheet1").Range("N" & Rows.Count).End(xlUp)))
   For i = 1 To UBound(Ary, 2)
      If InStr(1, Ary(1, i), ".") > 0 Then
         j = j + 1
         ReDim Preserve Nary(1 To UBound(Ary, 1), 1 To j)
         For k = 1 To UBound(Ary, 1)
         Nary(k, j) = Ary(k, i)
      Next k
      End If
   Next i
   Sheets("Sheet2").Range("A1").Resize(j, UBound(Nary)).Value = Application.Transpose(Nary)
End Sub
 
Last edited:
Upvote 0

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Nevermind, had to be something on my end. It's copying A:N like you said, but it's only doing it for the first criteria found. So I only get one line on Sheet2
 
Upvote 0
I'm not sure why, but my data only went as far as column G. I changed the N to G, and it started working fine. Thanks again. I really appreciate all your help. Now, if I can only figure out how it actually works XD.
 
Upvote 0
Glad to help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,966
Messages
6,175,662
Members
452,666
Latest member
AllexDee

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