Setting up an Array on a Macro

squeakums

Well-known Member
Joined
May 15, 2007
Messages
823
Office Version
  1. 365
This is my problem. I need to setup an array to look in 408 or so names and I don't want to have to write ("billy", "beth", ... ) etc - I just want it to scan array A3:A408 instead and unsure how to write the macro to do this. Any help would be appreciated. This is what I have so far:

Sub Echo_Monthly_CSR_June()
'
' Macro8 Macro
' Macro recorded 6/21/2008 by Kelly Simcik
'

'
Windows("Monthly Macro Insert.xls").Activate
Sheets("CSR Data").Select
Dim MyArray As Variant, x As Long, c As Range

'Assuming your Source, book = Monthly Macro Insert.xls and Sheet = Copy & Paste Echo
'Also assuming your Destination, book = Monthly Macro Insert.xls and sheets = CSR Data

MyArray = Array("A3:A408").Select

For x = 0 To 405
With Workbooks("Monthly Macro Insert.xls").Sheets("Copy & Paste Echo")
Set c = .Cells.Find(What:=MyArray(x), After:=.Range("A1"), LookIn:=xlFormulas, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
False, SearchFormat:=False)
If Not c Is Nothing Then
c.Offset(0, 2).Copy
Workbooks("Monthly Macro Insert.xls").Sheets("CSR Data").Range("B" & x + 3).PasteSpecial xlPasteValues
If Not c Is Nothing Then
c.Offset(0, 5).Copy
Workbooks("Monthly Macro Insert.xls").Sheets("CSR Data").Range("C" & x + 3).PasteSpecial xlPasteValues
End If
End If
End With
Next x
Range("A1").Select
Windows("Weekly Macro Insert.xls").Activate
Sheets("Supervisor Echo Results").Select
Range("B2:V28").Select
Selection.Replace What:="", Replacement:="N/A", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Range("A1").Select
Windows("Weekly Macro Insert.xls").Activate
Sheets("Macro").Select
Range("A1").Select

End Sub
 
There is a mismatch between the index of MyArray and the row number it came from. This is one fix, but Jindon's suggestion that you use a For Each loop is the way I would go.
Code:
For X = 1 to 366
 
Upvote 0

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.

Forum statistics

Threads
1,215,679
Messages
6,126,177
Members
449,296
Latest member
tinneytwin

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