+ Reply to Thread
Results 1 to 2 of 2

VBA error Next Without For - applying macro to select worksheets

Hybrid View

  1. #1
    Registered User
    Join Date
    01-14-2013
    Location
    United States
    MS-Off Ver
    Excel 2003
    Posts
    18

    VBA error Next Without For - applying macro to select worksheets

    I am having trouble running the following code. Basically I am trying to run a macro that applies data validation and circles the errors across worksheets. I dont want this across all worksheets, only across those I select or define (preferably select by grouping them. Can anyone tell what I am doing wrong??

    Sub data_validation_names()
    '
    ' data_validation_names Macro
    '
    ' Keyboard Shortcut: Ctrl+p
    '

    Dim mySelectedSheets As Sheets
    Dim wks As Worksheet
    Application.ScreenUpdating = False

    Set mySelectedSheets = ActiveWindow.SelectedSheets

    For Each wks In mySelectedSheets
    wks.Activate

    With wks
    Range("C6:C31").Select
    ActiveWindow.SmallScroll Down:=-18
    With Selection.Validation
    .Delete
    .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
    xlBetween, Formula1:="='Singers summary'!$b$2:$b$189"
    .IgnoreBlank = True
    .InCellDropdown = True
    .InputTitle = ""
    .ErrorTitle = ""
    .InputMessage = ""
    .ErrorMessage = ""
    .ShowInput = True
    .ShowError = True
    End With
    Range("A6:A25").Select
    ActiveWindow.SmallScroll Down:=-39
    With Selection.Validation
    .Delete
    .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
    xlBetween, Formula1:="='Singers summary'!$A$2:$A$189"
    .IgnoreBlank = True
    .InCellDropdown = True
    .InputTitle = ""
    .ErrorTitle = ""
    .InputMessage = ""
    .ErrorMessage = ""
    .ShowInput = True
    .ShowError = True
    End With
    ActiveSheet.CircleInvalid
    Next wks
    Application.ScreenUpdating = True
    Set mySelectedSheets = Nothing

    End Sub

  2. #2
    Registered User
    Join Date
    11-13-2006
    Posts
    87

    Re: VBA error Next Without For - applying macro to select worksheets

    I'm going to stop right here
    Dim mySelectedSheets As Sheets
    Can't do that. Try:
    Dim MySelectedSheets As Collection
    If ActiveWindow.SelectedSheets is also a Collection, you should be good to go. Otherwise you'll have to loop thru SelectedSheets and .Add them to mySelectedSheets.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Applying a macro to all worksheets in workbook
    By samz93 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-07-2013, 02:47 AM
  2. [SOLVED] Applying Macro across several worksheets
    By daniel_t in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-31-2012, 02:08 PM
  3. [SOLVED] Applying Macro to all worksheets (tabs)
    By CBailey84 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-16-2012, 10:46 AM
  4. Applying a Macro to multiple worksheets
    By JD1 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-19-2007, 12:15 PM
  5. Applying same macro to all worksheets in workbook
    By jsadd1@gmail.com in forum Excel General
    Replies: 2
    Last Post: 10-19-2005, 07:05 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1