PDA

View Full Version : Find Next Error



stoggie
02-05-2007, 07:39 AM
Having some difficulty with the macor and hoping someone will be able to help.
Macro:
***********

Sub MacroPAK()
'
'
'
Sheets("PIVOT").Select
For i = 0 To 100
'Note: This goes to 100 since there might be up to 100 rows in the pivot table of CISCOs.
Sheets("PIVOT").Range("A5").Select
Sheets("PIVOT").Range("A5").Activate
'Note: A5 being the location of the first cell in the CISCO column of the pivot table
If ActiveCell.Offset(i, 0).Value <> Sheets("Sheet2").Range("B5").Value Then
Next i
'Note: "If not a match, then go on to the next row in the pivot table."
'Note: Activecell.offset(i,0) looks at the cell i rows down and 0 columns over from the active cell (which is A5)
'Note: B6 is the cell on the Cover Page that holds the user's selection.
Else
ActiveCell.Offset(i, 1).Select
'Note: This command selects the data cell 1 row over from the matching CISCO.
'Note: If the data cell is a different number of rows over, change the "1" appropriately.
Selection.ShowDetail = True
'Note: This command brings up all the detail behind that pivot table data cell.
Next i
End If
'Note: "If match is found, stop searching and give control back to the user."
End Sub
*************
The "Next is highlighted with the Error: "Next without For". But there is a For.

Then I change the Next to "SelectRange.FindNext", another error appears with the End Sub highlighted: "For without Next"

Any help is GREATLY appreciated.

Bob Phillips
02-05-2007, 07:55 AM
Sub MacroPAK()
'
'
'
With Sheets("PIVOT").Range("A5")
For i = 0 To 100
If .Offset(i, 0).Value = Sheets("Sheet2").Range("B5").Value Then
.Offset(i, 1).ShowDetail = True
End If
Next i
End With
End Sub

stoggie
02-05-2007, 08:00 AM
Thanks for the fast response. Works GREAT!

gnod
02-05-2007, 08:04 AM
good programming practice is to indent your code.. by doing that, you will see what did you missed..

mdmackillop
02-05-2007, 08:07 AM
Hi Stoggie,
When you post code, please select it and click on the VBA button which will indent it as shown. When indented, your error becomes quite apparent.
You can either indent your code manually or automaticallty (see my signature).