+ Reply to Thread
Results 1 to 9 of 9

use vba code to change other vba code

  1. #1
    Registered User
    Join Date
    06-05-2012
    Location
    israel
    MS-Off Ver
    Excel 2007
    Posts
    3

    use vba code to change other vba code

    Hi all,

    Does anyone know how i can use a vba code to change,edit,modify, other vba code ?

    say for example i have the following code :

    sub main()

    Range("A1")=1

    End Sub

    and i want to use a new code that will enter the main() subroutine and change Range("A1") to be,say, Range("B1")

    Regards,
    Alon

  2. #2
    Forum Contributor
    Join Date
    02-12-2012
    Location
    South Africa
    MS-Off Ver
    Excel 2007
    Posts
    275

    Re: use vba code to change other vba code

    Will this change be once off or repeated?

    When must this code change?

  3. #3
    Registered User
    Join Date
    06-05-2012
    Location
    israel
    MS-Off Ver
    Excel 2007
    Posts
    3

    Re: use vba code to change other vba code

    dear evertjvr,

    The change will be repeated
    the original code will be changed when i choose to run the new code with a command button
    the question is how to tell the code to choode the Range("a1") code and change it to Range("b1")

    Regards,
    Alon

  4. #4
    Forum Contributor
    Join Date
    02-12-2012
    Location
    South Africa
    MS-Off Ver
    Excel 2007
    Posts
    275

    Re: use vba code to change other vba code

    Here is possable solution

    Please Login or Register  to view this content.
    for some reason the variable c needs to be "conditioned" for the column reference and i do that with c = c +1 - 1

    The c value can also be populated in various other ways like from a cell value or cell selection.

  5. #5
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,994

    Re: use vba code to change other vba code

    Or c=c+0, c=--c, c*1, maybe?
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  6. #6
    Forum Contributor
    Join Date
    02-12-2012
    Location
    South Africa
    MS-Off Ver
    Excel 2007
    Posts
    275

    Re: use vba code to change other vba code

    Why does the variable for c need conditioning when used for column reference but not for row reference?

  7. #7
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,994

    Re: use vba code to change other vba code

    I don't know how you normally get your row reference.

    In this case, c isn't Dimmed as long and InputBox would give you a text value ... which you need to convert to numeric.

    Regards, TMS

  8. #8
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,447

    Re: use vba code to change other vba code

    It seems to me you could use and Indirect() function in a sheet to do some simple changing that would not require any VBA change.

    I think other than that you'd have to create variables that find their values from somewhere on your sheet or using an input box to change.
    see http://www.cpearson.com/excel/TrulyGlobalVariables.htm

    You might also look at Global or Public variables or simply having a cell that points you to what you want to grab. That would be like an Indirect().
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  9. #9
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: use vba code to change other vba code

    This is one way.

    Please Login or Register  to view this content.
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

+ 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