Consulting

Results 1 to 11 of 11

Thread: Vba Code Error

  1. #1

    Vba Code Error

    Dear All,

    Can you please help in solving this code

    [VBA]
    Private Sub CommandButton1_Click()


    If CheckBox1.Value = True Then
    Range("a1:b7").AutoFilter Field:=1, Criteria1:="A"

    GoTo jump1
    Else
    If CheckBox1.Value = False Then
    GoTo jump1
    jump1:
    If CheckBox2.Value = True Then
    Union(Selection, Range("a1:b7")).AutoFilter Field:=1, Criteria1:="B"

    GoTo jump2
    Else
    If CheckBox2.Value = False Then
    GoTo jump2
    jump2:
    If CheckBox3.Value = True Then
    Union(Selection, Range("a1:b7")).AutoFilter Field:=1, Criteria1:="C"


    End If
    End If
    End If
    End If
    End If
    End Sub
    [/VBA]

    Regards,
    Srivardhan

    Edit: Please use the VBA button instead of the quote button to format your code.

  2. #2
    VBAX Regular
    Joined
    Oct 2009
    Location
    Fremont, CA
    Posts
    72
    Location

    Please provide more details

    Gee! It sure would help if you were to tell us what you are trying to accomplish with this code...

  3. #3
    Knowledge Base Approver VBAX Guru GTO's Avatar
    Joined
    Sep 2008
    Posts
    3,368
    Location
    Greetings Srivardhan,

    Say, I see it is your first post and that you just joined. Let me say 'Welcome' and a friendly 'Howdy' from Arizona. You will 'meet' some nice folks here and get great help

    As you your current problem, I'd certainly agree with Rolf in that it is unclear. I'm just getting a teeny bit better w/filtering, but I tried making a simple example sheet, and although I doubt the GoTo's are the optimum, nothing "blew up" or anything.

    You may wish to attach an example workbook, which you can do by:
    • Press the Go Advanced button under the Quick Reply box; this will take you to a new window.
    • Below the larger reply box, press the Manage Attachments button.
    Hope that helps,

    Mark

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Doesn't this code (and the next such example) seem a tad pointless to you?

    [vba]

    If CheckBox1.Value = False Then
    Goto jump1
    jump1:
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  5. #5
    Dear All,

    Nice to meet you all.....

    The Problem what i am facing is

    've got a sheet with some 40 or so check boxes representing project requirements. I also have a list of ~200 text filled cells, each of which correspond to necessary actions. What I'm trying to determine is the code to allow me to select certain cells from the list based on the check box(s) selected. Different project requirements might share the same options.

    For example

    selecting checkbox1 might filter only "A"
    selecting checkbox2 might select cells "B"

    and selecting both (checkbox1 & checkbox2) would filter for "A" & "B"

    Any ideas would be appreciated.


    Please help me get out of this problem

  6. #6
    Dear All,

    Below is the code that works for selecting the records using check boxes.

    [VBA]Private Sub CommandButton1_Click()
    If CheckBox1.Value = True Then
    Range("a1:b5").Select

    GoTo jump1
    Else
    If CheckBoxML.Value = False Then
    GoTo jump1
    jump1:
    If CheckBox2.Value = True Then
    Union(Selection, Range("a6:b10")).Select
    GoTo jump2
    Else
    If CheckBox2.Value = False Then
    GoTo jump2
    jump2:
    If CheckBox3.Value = True Then
    Union(Selection, Range("a10:b15")).Select


    End If
    End If
    End If
    End If
    End If[/VBA]

    If i am using autofilter it is not working

    [VBA]Private Sub CommandButton1_Click()


    If CheckBox1.Value = True Then
    Range("a1:b7").AutoFilter Field:=1, Criteria1:="A"

    GoTo jump1
    Else
    If CheckBox1.Value = False Then
    GoTo jump1
    jump1:
    If CheckBox2.Value = True Then
    Union(Selection, Range("a1:b7")).AutoFilter Field:=1, Criteria1:="B"

    GoTo jump2
    Else
    If CheckBox2.Value = False Then
    GoTo jump2
    jump2:
    If CheckBox3.Value = True Then
    Union(Selection, Range("a1:b7")).AutoFilter Field:=1, Criteria1:="C"


    End If
    End If
    End If
    End If
    End If
    End Sub[/VBA]

    Regards,
    Srivardhan
    Last edited by srivardhan09; 12-02-2009 at 10:26 AM. Reason: Not formatted correctly.....

  7. #7
    Dear Xld,

    What you said is correct... i will remove that else statement and increase the performance...

    Thank You for your valid suggestion....

    Regards,
    Srivardhan

  8. #8
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    The proble is that autofilter canot handle 40 criteria, so it cannot be used with 40 checkboxes.

    Is Advanced filter an option, as we could build a criteria list for that.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  9. #9
    Is there any other option for selecting one or more check boxes based on condition.

  10. #10
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    It isn't the selecting of the checkboxes, it is using them.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  11. #11
    Yes... can you please help regrading that code i am trying from past 4 days... totally vexed up!!!

Posting Permissions

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