Stop a simple macro

  • Thread starter Thread starter Dee
  • Start date Start date
D

Dee

Hi,

Below is a simple macro run to show detail of a pivot table on a required
field.
May I know what shall i do to stop the macro if the pivot table don't contain
the respective field ??

******************************************************
Worksheets("Pivot Table 1")Activate
For i = 26 To 60
If Cells(i, "u") = "Key" Then
Cells(i, "v").Select
Selection.ShowDetail = True
Exit For
End If
Next i

Thanks in advance !!
 
Use a flag to determine if the match occurred and take action:

Sub servient()
Worksheets("Pivot Table 1")Activate
got_it = False
For i = 26 To 60
If Cells(i, "u") = "Key" Then
got_it = True
Cells(i, "v").Select
Selection.ShowDetail = True
Exit For
End If
Next i
If got_it = False Then
Exit Sub
End If
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top