Results 1 to 4 of 4

Thread: Concatenation question

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2004
    Posts
    2

    Concatenation question

    Is there any concatenation for anything but strings? I have several check boxes in an excel sheet.

    checkbox1
    checkbox2
    checkbox3..... etc

    I would like to run concantenation within a loop where I do something like this sudo code....


    For N = 1 to 10 Step 1

    If checkbox(N) = -1 Then

    do something

    End If

    Next N


    I have working code that does what I want, but I have an If.. Then statement for every box on the sheet. If I could collapse this into a loop it would clean up my code alot. The only concatenation references I can find only talk about text. Any suggestions?

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974
    instead of this:
    VB Code:
    1. If checkbox(N) = -1 Then

    try this:
    VB Code:
    1. If Controls("checkbox" & N) = -1 Then

    or this:
    VB Code:
    1. If FormName.Controls("checkbox" & N) = -1 Then
    (where FormName is the name of the form)

  3. #3

    Thread Starter
    New Member
    Join Date
    Mar 2004
    Posts
    2
    hmm.... the only thing I did was open up the design mode and use the tool box to drop my check boxes on to the spreadsheet. I didn't add a form. I added a module1 to put all my code in because for some reason it would only let me do two Sub type proceedures in the edit code for my button to start the process. Now that I am home here is a snipit of the code I would like to edit by a loop. SLevel0 is the name of the check box. I have several like SLevel1, SLevel2... so thus I would like to put the N/Level in the numbers area.

    For Level = 0 To 9 Step 1
    If S = True And (Sheets("Sheet1").SLevel0.Value = -1) Then
    For N = 1 To 300 Step 1
    If (Sheets("Sheet3").Cells(N, 2) = Level) And (Sheets("Sheet3").Cells(N, 25) = "Simple") Then
    Sheets("Sheet2").Cells(tracker, 1) = Sheets("Sheet3").Cells(N, 1)
    tracker = tracker + 1
    End If
    Next N
    End If

    If C = True And (Sheets("Sheet1").CLevel0.Value = -1) Then
    For N = 1 To 300 Step 1
    If (Sheets("Sheet3").Cells(N, 2) = Level) And (Sheets("Sheet3").Cells(N, 25) = "Complex") Then
    Sheets("Sheet2").Cells(tracker, 1) = Sheets("Sheet3").Cells(N, 1)
    tracker = tracker + 1
    End If
    Next N
    End If

    If E = True And (Sheets("Sheet1").ELevel0.Value = -1) Then
    For N = 1 To 300 Step 1
    If (Sheets("Sheet3").Cells(N, 2) = Level) And (Sheets("Sheet3").Cells(N, 25) = "Exotic") Then
    Sheets("Sheet2").Cells(tracker, 1) = Sheets("Sheet3").Cells(N, 1)
    tracker = tracker + 1
    End If
    Next N
    End If

    tracker = tracker + 1
    Next Level

  4. #4
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974
    ok.. for a Worksheet it seems controls are stored as Shapes, so try this:
    VB Code:
    1. For Level = 0 To 9 Step 1
    2.   If S = True And (Sheets("Sheet1").Shapes("SLevel" & Level).Value = -1) Then

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width