+ Reply to Thread
Results 1 to 10 of 10

Automatic Change in Code

Hybrid View

  1. #1
    Registered User
    Join Date
    06-13-2007
    Posts
    58

    Red face Automatic Change in Code

    Is there any way, in which i can make my code dynamic?? For example, in a code written in VBA, there is a reference to particular sheet, say "ABC". If i change the name from "ABC" to "ABCD" from excel, the underlying code should change automatically from "ABC" to "ABCD".

    I want to make my code dynamic..

    I hope u get my problem... can any1 help me on this??
    Last edited by crapmind; 06-16-2007 at 04:04 PM.

  2. #2
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    Say the sheet tab is always say sheet 3 then use the number

    e.g

    Sheets(3).Activate
    HTH

    VBA Noob
    _________________________________________


    Credo Elvem ipsum etian vivere
    _________________________________________
    A message for cross posters

    Please remember to wrap code.

    Forum Rules

    Please add to your signature if you found this link helpful. Excel links !!!

  3. #3
    Registered User
    Join Date
    06-13-2007
    Posts
    58
    where to paste the code??

  4. #4
    Registered User
    Join Date
    06-13-2007
    Posts
    58
    even after pasting the code... its showing an error "Subscript out of range" whenever i change the name and re-run the macro

  5. #5
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    What sheet number is your sheet ??


    VBA Noob

  6. #6
    Registered User
    Join Date
    06-13-2007
    Posts
    58
    c the code

     Sub GetFalseItems()
    
    Dim Counter As Integer
    
    Counter = 5
    
    Worksheets("PLA").Range("A5:AD100").ClearContents
    
    For Each c In Worksheets("060107").Range("A1: A200")
        If c.Offset(0, 8).Value = "False" Then
            Worksheets("PLA").Range("A" & Counter).Value = c.Value
            Counter = Counter + 1
        End If
    Next c
    
    End Sub

    #

    This code is written in "ThisWorkbook"

    There are another 30 sheets "060107" series... like "060207", "060307" etc.

    Now if i change the name of the sheet "PLA" from Excel then the macro does not run. same as with other sheet.

    Is there any way in which i can make things dynamic.. so that even some user changes the name from excel itself, the code should adjust automatically and macro should run as before.
    Last edited by VBA Noob; 06-17-2007 at 11:40 AM.

+ Reply to Thread

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