+ Reply to Thread
Results 1 to 4 of 4

Multiple ComboBoxes - Is it possible to shorten code?

Hybrid View

  1. #1
    Registered User
    Join Date
    01-05-2015
    Location
    Wisconsin
    MS-Off Ver
    2013
    Posts
    50

    Multiple ComboBoxes - Is it possible to shorten code?

    I have multiple ComboBoxes (some of the code is below) and I was wondering if there is a way to shorten it up?

    Cross-posted here: http://www.mrexcel.com/forum/excel-q...rten-code.html

        With Sheet1.ComboBox2111
        .AddItem "00:00"
        For i = 1 To 1439
        .AddItem Format(i / 1440, "hh:mm")
        Next i
        End With
        With Sheet1.ComboBox2112
        .AddItem "00:00"
        For i = 1 To 1439
        .AddItem Format(i / 1440, "hh:mm")
        Next i
        End With
        With Sheet1.ComboBox2113
        .AddItem "00:00"
        For i = 1 To 1439
        .AddItem Format(i / 1440, "hh:mm")
        Next i
        End With
        With Sheet1.ComboBox2114
        .AddItem "00:00"
        For i = 1 To 1439
        .AddItem Format(i / 1440, "hh:mm")
        Next i
        End With
      With Sheet1.ComboBox2115
        .AddItem "00:00"
        For i = 1 To 1439
        .AddItem Format(i / 1440, "hh:mm")
        Next i
        End With
    Last edited by ocnmel; 01-07-2015 at 12:51 PM. Reason: Added Code Tags

  2. #2
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,998

    Re: Multiple ComboBoxes - Is it possible to shorten code?

    Please use code tags.

    Yes, you can do it in a loop:
    Dim n as Long
    for n = 2111 to 2115
    With Sheet1.OLEObjects("ComboBox" & n).Object
    .AddItem "00:00"
    For i = 1 To 1439
    .AddItem Format(i / 1440, "hh:mm")
    Next i
    End With
    next n
    Everyone who confuses correlation and causation ends up dead.

  3. #3
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: Multiple ComboBoxes - Is it possible to shorten code?

    Something like this
        Dim i As Long, x
        x = [index(text((row(1:1440)-1)/1440,"hh:mm"),,)]
        For i = 2111 To 2115
            Sheet1.OLEObjects("Combobox" & i).Object.List = x
        Next

  4. #4
    Registered User
    Join Date
    01-05-2015
    Location
    Wisconsin
    MS-Off Ver
    2013
    Posts
    50

    Re: Multiple ComboBoxes - Is it possible to shorten code?

    Thank you both for your time and assistance. It is greatly appreciated!

+ 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. Shorten lengthy VBA Code to delete rows of data outside of multiple criteria
    By orenjisoda in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-20-2014, 09:49 PM
  2. How to set up multiple Activex comboboxes using the same code (dashboard)
    By jane serky in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-05-2013, 10:17 AM
  3. [SOLVED] Very inefficient code because of different sizes of arrays, how do i shorten my code?
    By Brammer88 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-28-2012, 04:49 PM
  4. Can I use one fill code to fill comboboxes in multiple forms?
    By 0612Man in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-18-2012, 02:57 PM
  5. make vba code for multiple comboboxes
    By Davo in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-04-2010, 01:26 AM

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