Results 1 to 9 of 9

Thread: Correct myCode please

  1. #1

    Thread Starter
    New Member
    Join Date
    Dec 2009
    Posts
    9

    Correct myCode please

    Please some one correct following code in VBA.

    cmb = 6
    If Sheet1.ComboBox & cmb.Text = "15 Days" Then sl_by = 2
    If Sheet1.ComboBox & cmb.Text = "30 Days" Then sl_by = 1


    Thank You

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Correct myCode please

    Thread Moved
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3
    Frenzied Member
    Join Date
    Jul 2009
    Posts
    1,103

    Re: Correct myCode please

    Quote Originally Posted by erksarma View Post
    Please some one correct following code in VBA.

    cmb = 6
    If Sheet1.ComboBox & cmb.Text = "15 Days" Then sl_by = 2
    If Sheet1.ComboBox & cmb.Text = "30 Days" Then sl_by = 1


    Thank You
    if you replace the second line of your code by the value of cmb i.e,6 then it becomes 6.text.......does it have any meaning

  4. #4
    Fanatic Member
    Join Date
    Sep 2006
    Location
    London, UK
    Posts
    817

    Re: Correct myCode please

    deleted.. I understand now and can't help.
    Last edited by sgrya1; Jan 22nd, 2010 at 07:50 AM.

  5. #5
    Lively Member
    Join Date
    Dec 2007
    Posts
    76

    Re: Correct myCode please

    What problem do you want to solve with this code?

  6. #6
    Fanatic Member
    Join Date
    Sep 2006
    Location
    London, UK
    Posts
    817

    Re: Correct myCode please

    I think I understand the problem. There are a number of comboboxes named ComboBox1 to say ComboBox9.

    VBA doesn't use control arrays so it's a little difficult without writing
    If Sheet1.ComboBox6.Text = "15 Days" Then sl_by = 2
    dealing with each ComboBox seperately.

  7. #7
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Correct myCode please

    vb Code:
    1. cmb = 6
    2. If Sheet1.olebjects("combobox" & cmb).object.Text = "15 Days" Then sl_by = 2
    3. If Sheet1.olebjects("combobox" & cmb).object.Text = "30 Days" Then sl_by = 1
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  8. #8

    Thread Starter
    New Member
    Join Date
    Dec 2009
    Posts
    9

    Re: Correct myCode please

    Thank U one and all especially westconn1.

    westconn1 reply helped me Thank You once again. I take u for my guru. I am an ameture. Please help me in the following problem.

    with the same project, as it may be clear to you I have placed some more controls in my workbook. They include DatePickers, Lables, Combos and CommondButtons etc., and some User Defined Functions. I am trying to distribute my work to my other offices. Some of the systems are not supporting the DatePickers. Probobly the references of VB controls are not activiated on those machines. I would like to give them a bundle of all such controls and UDFs so that tehy can use my workbook as I do on my machine. Help solicited please.

  9. #9
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Correct myCode please

    you can export modules with udfs, then import on other machines
    a simpler solution, might be to build an excel addin (.xla), which can be distributed to all users
    don't know about the datepickers, check for any missing references on machines where they don't work
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

Tags for this Thread

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