Compare Active Cell to Array in VBA

OO7Goofy

New Member
Joined
Jul 10, 2018
Messages
13
I'm working on a rather large project and one piece of it is to search for a specific column header then go down that row and search for certain values, all of which are text. It will then copy the entire row to a new worksheet. Is there an easy array search function? Below is an example of where i'm currently at with this subroutine.

Code:
Sub Arrange()


Dim wsP As Worksheet
Dim wsD As Worksheet
Dim i As Integer
Dim c As Integer
Dim FinalRow As Integer
    FinalRow = Sheets("Paste Here").Range("E10000").End(xlUp).Row
Dim CS As String
	LastNames = array("Duck", "Hunter", "Downer")
	FirstNames = array("John", "Jim", "David")


Set wsP = Worksheets("Paste Here")
Set wsD = Worksheets("Data")


Sheets("Paste Here").Select
Range("A1").Select




With wsP.Range("A1")


For i = 1 To FinalRow
c = 0
d = 1
CS = ActiveCell


Select Case CS
    Case Is = FirstNames(2)
    	ActiveCell.Offset(1, 0).Select
	If ActiveCell = FirstNames(x) Then
		ActiveCell.EntireRow.Copy Destination:=wsD.Cells(d + 1, 1)
                ActiveCell.Offset(1, 0).Select
                d = d + 1
        Else
        	ActiveCell.Offset(1, 0).Select
        End If


    Case Else
        ActiveCell.Offset(0, 1).Select


End Select
    
Next i 
    
End With


Set wsP = Nothing
Set wsD = Nothing


Range("A1").Select


End Sub
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Tell me what column are we going to search and search for what.

Copy from sheet is name "Data" and paste to sheet is named "Paste Here" is this correct

Please do not say read my script.
 
Upvote 0
Apologies for any misunderstanding in wording. "Paste Here" is where individuals will paste their information and then click run macro. I have a separate page "Data" where I organize the information. Multiple people will be using this program and often the columns of the data that they input are not in a specific order. The column names will always be the same.

So 1st, I need to find Column "x" then I need to go down that column and search for specific values. Once I find those values, I want to copy that row to the "Data" sheet.

Thank you for the help.
 
Upvote 0

Forum statistics

Threads
1,216,115
Messages
6,128,923
Members
449,479
Latest member
nana abanyin

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