+ Reply to Thread
Results 1 to 5 of 5

for Looping in VBA/Form

  1. #1
    Excel 2003 - SPB
    Guest

    for Looping in VBA/Form

    I have many areas of code that could be cleaned if I only knew how
    I think it would be a "For" statement in both cases
    example 1
    Pax1.Caption = Range("d5")
    Pax2.Caption = Range("d6")
    Pax3.Caption = Range("d7")
    etc
    example 2
    TextBox31.Visible = False
    TextBox32.Visible = False
    TextBox33.Visible = False

    I tried this

    For i = 1 To 6

    Seat " & i &.Caption = Range(""a" & i + l2 & """)"
    next i

    with no luck, I get a compile error highlighting "Seat"

    Many thanks for any help

  2. #2
    Toppers
    Guest

    RE: for Looping in VBA/Form



    For i = 1 To 3
    Controls("Pax" & i).Caption = Range("d" & i+4)
    Next i


    For i = 31 To 33
    Controls("Textbox" & i).Visible = False
    Next i

    HTH

    "Excel 2003 - SPB" wrote:

    > I have many areas of code that could be cleaned if I only knew how
    > I think it would be a "For" statement in both cases
    > example 1
    > Pax1.Caption = Range("d5")
    > Pax2.Caption = Range("d6")
    > Pax3.Caption = Range("d7")
    > etc
    > example 2
    > TextBox31.Visible = False
    > TextBox32.Visible = False
    > TextBox33.Visible = False
    >
    > I tried this
    >
    > For i = 1 To 6
    >
    > Seat " & i &.Caption = Range(""a" & i + l2 & """)"
    > next i
    >
    > with no luck, I get a compile error highlighting "Seat"
    >
    > Many thanks for any help


  3. #3
    Bob Phillips
    Guest

    Re: for Looping in VBA/Form

    For i = 1 To 10
    me.Controls("Pax" & i).Caption = Range("D" & i + 4).Value
    Next i

    etc.

    --
    HTH

    Bob Phillips

    (replace somewhere in email address with gmail if mailing direct)

    "Excel 2003 - SPB" <[email protected]> wrote in message
    news:[email protected]...
    > I have many areas of code that could be cleaned if I only knew how
    > I think it would be a "For" statement in both cases
    > example 1
    > Pax1.Caption = Range("d5")
    > Pax2.Caption = Range("d6")
    > Pax3.Caption = Range("d7")
    > etc
    > example 2
    > TextBox31.Visible = False
    > TextBox32.Visible = False
    > TextBox33.Visible = False
    >
    > I tried this
    >
    > For i = 1 To 6
    >
    > Seat " & i &.Caption = Range(""a" & i + l2 & """)"
    > next i
    >
    > with no luck, I get a compile error highlighting "Seat"
    >
    > Many thanks for any help




  4. #4
    Dave Peterson
    Guest

    Re: for Looping in VBA/Form

    Maybe...

    dim i as long

    for i = 1 to 3
    me.controls("Pax" & i).caption = cells(i+4,"D").value
    next i

    for i = 31 to 33
    me.controls("textbox" & i).visible = false
    next i

    But I don't see how either example comes close to the stuff you tried. Where
    does Seat fit in?

    Excel 2003 - SPB wrote:
    >
    > I have many areas of code that could be cleaned if I only knew how
    > I think it would be a "For" statement in both cases
    > example 1
    > Pax1.Caption = Range("d5")
    > Pax2.Caption = Range("d6")
    > Pax3.Caption = Range("d7")
    > etc
    > example 2
    > TextBox31.Visible = False
    > TextBox32.Visible = False
    > TextBox33.Visible = False
    >
    > I tried this
    >
    > For i = 1 To 6
    >
    > Seat " & i &.Caption = Range(""a" & i + l2 & """)"
    > next i
    >
    > with no luck, I get a compile error highlighting "Seat"
    >
    > Many thanks for any help


    --

    Dave Peterson

  5. #5
    Excel 2003 - SPB
    Guest

    RE: for Looping in VBA/Form



    "Toppers" wrote:

    >
    >
    > For i = 1 To 3
    > Controls("Pax" & i).Caption = Range("d" & i+4)
    > Next i
    >
    >
    > For i = 31 To 33
    > Controls("Textbox" & i).Visible = False
    > Next i
    >
    > HTH
    >
    > "Excel 2003 - SPB" wrote:
    >
    > > I have many areas of code that could be cleaned if I only knew how
    > > I think it would be a "For" statement in both cases
    > > example 1
    > > Pax1.Caption = Range("d5")
    > > Pax2.Caption = Range("d6")
    > > Pax3.Caption = Range("d7")
    > > etc
    > > example 2
    > > TextBox31.Visible = False
    > > TextBox32.Visible = False
    > > TextBox33.Visible = False
    > >
    > > I tried this
    > >
    > > For i = 1 To 6
    > >
    > > Seat " & i &.Caption = Range(""a" & i + l2 & """)"
    > > next i
    > >
    > > with no luck, I get a compile error highlighting "Seat"
    > >
    > > Many thanks for any help



    Great! I knew it would be simple
    Thanks to both of 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