Shippwreck
Programmer
Hi Everyone,
I've been coding in VBA for a little bit now, but still consider myself a beginner, basically i get most things done by recording a bit and then adapting that code to what i need. This works well and i can do a lot of things this way except i don't really understand the errors that pop up and still don't really understand all of the explanation to them either.
So this causes a problem with the above error as my method breaks down. Here it is, I need to search a selection to find a certain piece of text, this search needs to be repeated about 50 times or so with different text. To achieve this i created an array to contain the values and then loop through the search the number of times in the array. Below is the code, should make it clearer:
Do
If ArrayName1(Number1) = "END" Then
Exit Do
Else
Set c = Cells.Find(What:=ArrayName1(Number1), LookAt:=xlPart)
If c Is Nothing Then
Number1 = Number1 + 1
Else
Range("A9:A1000").Select
********Selection.Find(What:=ArrayName1(Number1), LookAt:=xlPart).Activate********
Range("A9:A1000").Select
Row1 = ActiveWindow.Selection.Row
CellSelection1 = ("D" & Row1)
Range(CellSelection1).Copy
Windows("Working File V3.xls").Activate
Sheets("Base Data Q1 04 - 05").Select
Cells.Find(What:=ArrayName1(Number1), _ LookAt:=xlWhole).Activate
Row2 = ActiveWindow.Selection.Row
CellSelection2 = ("E" & Row2)
Range(CellSelection2).Select
ActiveSheet.Paste
Number1 = Number1 + 1
Windows("data.xls").Activate
Sheets("code").Select
End If
End If
Loop
It is the bit with stars around that VB highlights in yellow when i debug. Just to make it a little bit more complicated i have 9 different arrays so in a form that appears before this loop i assign which array i want to use to ArrayName1.
Just for som background if i take out Range("A9:A1000").Select and change Selection to Cells it works fine (but searches the whole sheet which i can't have) When i try my way of recording a search it gives:
Range("A9:A1000").Select
Selection.Find(What:="TAN", After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
And if i use that (except change the search to the array) it doesn't work. Therefore i have come to the conclusion that it is how i declare the array, which looks like this:
Public ArrayName1
Public STTCode 'Name of one of my arrays
Any help would be greatly appreciated, thanks a lot
I've been coding in VBA for a little bit now, but still consider myself a beginner, basically i get most things done by recording a bit and then adapting that code to what i need. This works well and i can do a lot of things this way except i don't really understand the errors that pop up and still don't really understand all of the explanation to them either.
So this causes a problem with the above error as my method breaks down. Here it is, I need to search a selection to find a certain piece of text, this search needs to be repeated about 50 times or so with different text. To achieve this i created an array to contain the values and then loop through the search the number of times in the array. Below is the code, should make it clearer:
Do
If ArrayName1(Number1) = "END" Then
Exit Do
Else
Set c = Cells.Find(What:=ArrayName1(Number1), LookAt:=xlPart)
If c Is Nothing Then
Number1 = Number1 + 1
Else
Range("A9:A1000").Select
********Selection.Find(What:=ArrayName1(Number1), LookAt:=xlPart).Activate********
Range("A9:A1000").Select
Row1 = ActiveWindow.Selection.Row
CellSelection1 = ("D" & Row1)
Range(CellSelection1).Copy
Windows("Working File V3.xls").Activate
Sheets("Base Data Q1 04 - 05").Select
Cells.Find(What:=ArrayName1(Number1), _ LookAt:=xlWhole).Activate
Row2 = ActiveWindow.Selection.Row
CellSelection2 = ("E" & Row2)
Range(CellSelection2).Select
ActiveSheet.Paste
Number1 = Number1 + 1
Windows("data.xls").Activate
Sheets("code").Select
End If
End If
Loop
It is the bit with stars around that VB highlights in yellow when i debug. Just to make it a little bit more complicated i have 9 different arrays so in a form that appears before this loop i assign which array i want to use to ArrayName1.
Just for som background if i take out Range("A9:A1000").Select and change Selection to Cells it works fine (but searches the whole sheet which i can't have) When i try my way of recording a search it gives:
Range("A9:A1000").Select
Selection.Find(What:="TAN", After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
And if i use that (except change the search to the array) it doesn't work. Therefore i have come to the conclusion that it is how i declare the array, which looks like this:
Public ArrayName1
Public STTCode 'Name of one of my arrays
Any help would be greatly appreciated, thanks a lot