Results 1 to 5 of 5

Running Same macro on Multiple sheets

Threaded View

  1. #1
    Registered User
    Join Date
    05-15-2013
    Location
    Australia
    MS-Off Ver
    Excel 2010
    Posts
    2

    Running Same macro on Multiple sheets

    Hi,

    I am new to VBA and have gone through all the codes for my problem but none of it is working.

    This is the code I want to run on Multiple sheets-
    ----------------------------------------------
    Sub Delete_Columns()
    
    Target1 = "Product Category"
    Target2 = "Total"
    Target3 = "TAS"
    
    Range("A1").Select
    Do Until ActiveCell.Value = ""
    If ActiveCell.Value = Target1 Or ActiveCell.Value = Target2 Then
    ActiveCell.EntireColumn.Delete
    Else
    ActiveCell.Offset(0, 1).Activate
    End If
    If ActiveCell.Value = Target3 Then
    ActiveCell = "TelephoneNumber"
    Else
    ActiveCell.Offset(0, 1).Activate
    End If
    loop
    end sub
    ------------------------------------

    This is the code with which I am trying to make it work on multiple sheets
    ---------------------------------------------
    Sub Delete_Columns()
    Dim intSheetIndex As Integer
    
    Target1 = "Product Category"
    Target2 = "Total"
    Target3 = "TAS"
    'I can add as many target columns I want
    
    For ws = (Sheets("AC").Index + 1) To (Sheets("Unassigned").Index - 1)
    Sheets(ws).Activate
    Range("A1").Select
    Do Until ActiveCell.Value = ""
    If ActiveCell.Value = Target1 Or ActiveCell.Value = Target2 Then
    ActiveCell.EntireColumn.Delete
    Else
    ActiveCell.Offset(0, 1).Activate
    End If
    If ActiveCell.Value = Target3 Then
    ActiveCell = "TelephoneNumber"
    Else
    ActiveCell.Offset(0, 1).Activate
    End If
    Next ws
    End Sub
    -----------------------------------

    This gives a compile error "Next without For". Please help.

    Thanks
    ~S
    Last edited by shilpigupta79; 07-01-2013 at 01:22 AM.

Thread Information

Users Browsing this Thread

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

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