+ Reply to Thread
Results 1 to 37 of 37

Iteration

  1. #1
    Registered User
    Join Date
    10-09-2009
    Location
    Sacramento, California
    MS-Off Ver
    Excel 2003
    Posts
    25

    Iteration

    I need a formula that will ask for the number of switches and then give a configuration....


    How many switches? 4



    The result should look like this:

    interface range GigabitEthernet1/0/1 - 48,GigabitEthernet2/0/1 - 48,GigabitEthernet3/0/1 - 48,GigabitEthernet4/0/1 - 48


    this is what I have so far:
    =REPT("GigabitEthernet, ()/0/1 - 48,",D1)

    I need the area in the parentheses to iterate to the number of switches

  2. #2
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    16,028

    Re: Iteration issue

    In same cell or can be in 4 columns (or any other when you type no of switches)
    Never use Merged Cells in Excel

  3. #3
    Registered User
    Join Date
    10-09-2009
    Location
    Sacramento, California
    MS-Off Ver
    Excel 2003
    Posts
    25

    Re: Iteration issue

    huh?

    Do you have a formula?

    Any examples?

  4. #4
    Forum Expert teylyn's Avatar
    Join Date
    10-28-2008
    Location
    New Zealand
    MS-Off Ver
    Excel 365 Insider Fast
    Posts
    11,372

    Re: Iteration issue

    Hi,

    zbor wants to know if you want the result all in one cell or in different columns.

    have a look at the attached.

    hth
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    10-09-2009
    Location
    Sacramento, California
    MS-Off Ver
    Excel 2003
    Posts
    25

    Re: Iteration issue

    Wow! That's way cool!! How did you get it to reference the number in the 1st column?

  6. #6
    Registered User
    Join Date
    10-09-2009
    Location
    Sacramento, California
    MS-Off Ver
    Excel 2003
    Posts
    25

    Re: Iteration issue

    oh...and I want the results to iterate in the same cell just like you have it in the example you posted...

  7. #7
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Iteration issue

    You'll struggle to come up with something truly dynamic (and elegant) in one cell without use of VBA (UDF) and/or 3rd party add-in like morefunc.xll (MCONCAT function)

    In UDF terms, the below stored in a Module

    Please Login or Register  to view this content.
    in a Macro Enabled file can be used along lines of:

    Please Login or Register  to view this content.
    where [X] denotes the placeholder position

    If you wanted to use an alternative delimiter (to comma) you can explicitly pass the otherwise optional 3rd argument, eg to use :

    Please Login or Register  to view this content.

  8. #8
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Iteration issue

    i'd go for a table approach as its easy enough to construct one for any interface type see sheet 2(once done you can simply copy paste back special values only to eliminate the formulas)

    then use a simple vlook up
    Attached Files Attached Files
    Last edited by martindwilson; 10-17-2009 at 06:38 AM.
    "Unless otherwise stated all my comments are directed at OP"

    Mojito connoisseur and now happily retired
    where does code go ?
    look here
    how to insert code

    how to enter array formula

    why use -- in sumproduct
    recommended reading
    wiki Mojito

    how to say no convincingly

    most important thing you need
    Martin Wilson: SPV
    and RSMBC

  9. #9
    Registered User
    Join Date
    10-09-2009
    Location
    Sacramento, California
    MS-Off Ver
    Excel 2003
    Posts
    25

    Re: Iteration issue

    @ DonkeyOte

    That worked beautifully!! Thank you so much, really appreciated! I had another scenerio I wanted to run by you...

    Suppose I want the first and last elements in the string to be different from what's in between such as the following:

    interface range GigabitEthernet1/0/51 - 52,GigabitEthernet2/0/49 - 52,GigabitEthernet3/0/49 - 52,GigabitEthernet4/0/51 - 52

    Thanks again,

    Anne
    Last edited by shg; 10-17-2009 at 12:42 PM. Reason: Deleted spurious quote

  10. #10
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Iteration issue

    Not quite sure I follow... you're altering the first element in sequence (ie 1 to n) but the 2nd appears perhaps random (?) - ie how do you determine logically as to whether or not the final element should be 49/51 ? (is it only first/last should be 51 ?)

  11. #11
    Registered User
    Join Date
    10-09-2009
    Location
    Sacramento, California
    MS-Off Ver
    Excel 2003
    Posts
    25

    Re: Iteration issue

    Yes, that's right...the first and the last elements will be 51 -52...and everything in between will be 49 - 52...All of these ports will be shut down....

    interface range GigabitEthernet1/0/51 - 52,GigabitEthernet2/0/49 - 52,GigabitEthernet3/0/49 - 52,GigabitEthernet4/0/49 - 52, GigabitEthernet5/0/49 - 52, GigabitEthernet6/0/51 - 52

    Thank you so much!

  12. #12
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Iteration issue

    Not very flexible going forward but perhaps:

    Please Login or Register  to view this content.
    Called

    Please Login or Register  to view this content.

  13. #13
    Registered User
    Join Date
    10-09-2009
    Location
    Sacramento, California
    MS-Off Ver
    Excel 2003
    Posts
    25

    Re: Iteration issue

    Wow, once again it worked! This is really cool! How did you learn how to do this?

  14. #14
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Iteration issue

    I'm glad it has worked for you.
    FWIW I don't get out much, however, in Excel what I don't know still exceeds that which I do.

    Please remember to mark thread as solved.

  15. #15
    Registered User
    Join Date
    10-09-2009
    Location
    Sacramento, California
    MS-Off Ver
    Excel 2003
    Posts
    25

    Re: Iteration issue

    Thank you so much for all your help with this....I guess I'm not versed enough in even basic vba to get the module placement right. I did a search and replace on one of the scripts that you put together replacing Switches with SWITCHES and the other SWITCHES1...added them to the VB code as Module1 and Module2. Now the cell registers as #NAME? I can't get it to work anymore... How can I make the scripts work for both scenerios?

    Thanks again,

    Anne

  16. #16
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Iteration issue

    You will need to post an example wherein you have placed your code - and where #NAME? errors are being generated...

    Note you can only have one function called SWITCHES else you will get an ambiguity error ie Switches and SWITCHES are one and the same as far as XL is concerned - this error will result in a #NAME? evaluation.

    If however the functions are stored in Modules in a macro-enabled VBA file you should find calling SWITCHES1 / SWITCHES should work without issue.

  17. #17
    Registered User
    Join Date
    10-09-2009
    Location
    Sacramento, California
    MS-Off Ver
    Excel 2003
    Posts
    25

    Re: Iteration issue

    I created a module as follows:

    Please Login or Register  to view this content.
    it worked initially...but after I save and close...it gives the #NAME? error now. Not sure what gives
    Last edited by ajducey; 10-28-2009 at 09:17 AM.

  18. #18
    Registered User
    Join Date
    10-09-2009
    Location
    Sacramento, California
    MS-Off Ver
    Excel 2003
    Posts
    25

    Re: Iteration issue

    Please Login or Register  to view this content.
    Last edited by ajducey; 10-28-2009 at 09:21 AM.

  19. #19
    Registered User
    Join Date
    10-09-2009
    Location
    Sacramento, California
    MS-Off Ver
    Excel 2003
    Posts
    25

    Re: Iteration issue

    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    I get the #NAME? error on both B2 and B3 cells
    Last edited by ajducey; 10-28-2009 at 09:20 AM. Reason: added code tags

  20. #20
    Registered User
    Join Date
    10-09-2009
    Location
    Sacramento, California
    MS-Off Ver
    Excel 2003
    Posts
    25

    Re: Iteration issue

    Here's some screen shots of the trouble... Thank you!
    Attached Files Attached Files

  21. #21
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Iteration issue

    The screenshot implies the file is being saved as .xlsm but are macros definitely being enabled when you open the file ?

    As I've said previously without seeing the file it's very hard to pass comment... #NAME? errors are generally result of

    a) macros not being enabled

    b) functions being stored in objects rather than Modules

    c) ambiguity (ie multiple functions of same name)

    There is nothing wrong with the two functions you have posted up and based on your screenshot the file is a macro compliant file type and the functions are stored in Modules so for me that leaves options a & c.

    To test macro enabled status... add the below to ThisWorkbook object (assumes you don't already have an open event in place!)

    Please Login or Register  to view this content.
    save & close the file, reopen file - do you get a MsgBox dialog ?

  22. #22
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Iteration issue

    EDIT:

    SCRAP THE ABOVE

    I just looked again... you've named the Modules the same as the Functions themselves (ambiguity) ... change the name of the modules to something other than the name of the Function (ie prefix the Module name with "fn" or "mod") and you should find things will work.

  23. #23
    Registered User
    Join Date
    10-09-2009
    Location
    Sacramento, California
    MS-Off Ver
    Excel 2003
    Posts
    25

    Re: Iteration issue

    that didn't work..changed to modSWITCHES and modSWITCHES1

  24. #24
    Registered User
    Join Date
    10-09-2009
    Location
    Sacramento, California
    MS-Off Ver
    Excel 2003
    Posts
    25

    Re: Iteration issue

    here's the file... thanks again!
    Attached Files Attached Files

  25. #25
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Iteration issue

    file works for me without issue... did you input my test re: workbook_open event ?

  26. #26
    Registered User
    Join Date
    10-09-2009
    Location
    Sacramento, California
    MS-Off Ver
    Excel 2003
    Posts
    25

    Re: Iteration issue

    I copy and pasted your code, it says the macros are disabled...how do I enable the macros? I thought by saving the file as xlsm that macros would be enabled...why did it work initially, then stop working? strange..

  27. #27
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Iteration issue

    For info. on managing VBA security in 2007 see: http://office.microsoft.com/en-gb/ex...969191033.aspx

  28. #28
    Registered User
    Join Date
    10-09-2009
    Location
    Sacramento, California
    MS-Off Ver
    Excel 2003
    Posts
    25

    Re: Iteration issue

    I got it...it's working now. Thank you so much for your patience!!!!

  29. #29
    Registered User
    Join Date
    10-09-2009
    Location
    Sacramento, California
    MS-Off Ver
    Excel 2003
    Posts
    25

    Re: Iteration issue

    Thanks again... I'd like to go on to create a form to take the information and spit out a text file with the config; but I'll start another thread for that....perhaps in the excel programming formum? How do I "mark this discussion as solved"?


    Thank you!!!

    Anne
    Last edited by ajducey; 10-30-2009 at 12:31 AM.

  30. #30
    Forum Expert teylyn's Avatar
    Join Date
    10-28-2008
    Location
    New Zealand
    MS-Off Ver
    Excel 365 Insider Fast
    Posts
    11,372

    Re: Iteration

    How do I "mark this discussion as solved"?
    Forum rule #10

    10. Please acknowledge the response you receive, good or bad. If your problem is solved, please say so clearly, and mark your thread as Solved: Click the Edit button on your first post in the thread, Click Go Advanced, select [SOLVED] from the Prefix dropdown, then click Save Changes. If more than two days have elapsed, the Edit button will not appear -- ask a moderator to mark it.

  31. #31
    Registered User
    Join Date
    10-09-2009
    Location
    Sacramento, California
    MS-Off Ver
    Excel 2003
    Posts
    25

    Re: Iteration

    "If more than two days have elapsed, the Edit button will not appear -- ask a moderator to mark it." It's been more than two days, could one of the moderators mark this as solved please? ...Thank you!

  32. #32
    Registered User
    Join Date
    10-09-2009
    Location
    Sacramento, California
    MS-Off Ver
    Excel 2003
    Posts
    25

    Re: Iteration

    I need this script to ask how many VLANS and if there's more than one VLAN. to assign the VLAN's to certain ports. Should I start a new post?

  33. #33
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    16,028

    Re: Iteration

    Perhapes that+s easier way: start new thread, explain problem, upload example...

  34. #34
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Iteration

    ...and as and when you do create the new thread please be sure to post any links should you choose to ask the question elsewhere -- and this would include LinkedIn

  35. #35
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Iteration

    all seems a long winded way to go about creating a cisco config if you ask me!

  36. #36
    Registered User
    Join Date
    10-09-2009
    Location
    Sacramento, California
    MS-Off Ver
    Excel 2003
    Posts
    25

    Re: Iteration

    ...not long winded when you consider I am mentoring people who have very little or no experience working with switches. This is a very effective means of preventing the wrong stuff getting provisioned into a switch. It really lessens the posibility of someone taking down a portchannel or fat fingering the wrong VLAN number. I like cookie-cutter consistency with configurations, it makes it easier to troubleshoot. The guy that I took this project over from left a big inconsistent mess with a lot of little elements to clean up. I'm still cleaning up that mess, although that in itself provided a really good opportunity for staff to get switch experience. Going forward though, everything will be very clean and in order.

  37. #37
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Iteration

    fair comment,must admit i have use of tools that automate loads of this but then again that solution would cost $10000's

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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