Results 1 to 1 of 1

VBA Excel checkbox results with If statement not correct

Threaded View

chaz1010 VBA Excel checkbox results... 02-16-2014, 06:15 AM
  1. #1
    Registered User
    Join Date
    10-08-2013
    Location
    Birmingham
    MS-Off Ver
    Excel 2007
    Posts
    3

    Cool VBA Excel checkbox results with If statement not correct

    Hi Guys,

    Hope you are well. I keep on going around in circles and really need some help.
    Okay, so I have got two worksheets. The first worksheet is called 'sheet1' and has two checkbox's called 'check1' and 'check2' and a button which pressed, executes the below code. The second worksheet is called 'results'.

    The worksheet 'results' is as follows : A1 = Monday, B1 = 1, C1 = 1
    A2 = Tuesday, B2 = 1, C2 = -4146
    A3 = Wednesday, B3 = -4146, C3 = 1
    A4 = Thursday,B4 = -4146, C4 = -4146

    Depending on the checkboxes ticked I want the below result to appear in ‘sheet1’:
    1)Check1 = ticked, check2 = ticked=> A1 = Monday, B1 = 1, C1 = 1 (works fine)
    2)Check1 = ticked, check2 = not ticked=> A1 = Monday, B1 = 1, C1 = 1
    A2 = Tuesday, B2 = 1, C2 = -4146 (does not work)
    3)Check1 = not ticked, check2 = ticked=> A1 = Monday, B1 = 1, C1 = 1
    A2 = Wednesday, B2 = -4146, C2 = 1(does not work)
    4)Check1 = not ticked, check2 = not ticked=>A1 = Thursday,B1 = -4146, C1 = -4146 (works fine)

    I am not sure where I am going wrong. I searched all over the web and loads of forums and can’t find a solution. It probably something really easy for you guys to resolve
    If you could help me, I would greatly appreciated it!
    Thanks
    Chaz


    Sub Macro1()
    
    Dim w As Long
    Dim s As Long
    w = 1
    s = 1
    Do While Worksheets("results").Range("A" & w) <> ""
    
    If ActiveSheet.Shapes("check1").ControlFormat.Value = Worksheets("results").Range("B" & w) And ActiveSheet.Shapes("check2").ControlFormat.Value = Worksheets("results").Range("C" & w) Then
    
    
    Worksheets("sheet1").Range("A" & s) = Worksheets("results").Range("A" & w)
    Worksheets("sheet1").Range("B" & s) = Worksheets("results").Range("B" & w)
    Worksheets("sheet1").Range("C" & s) = Worksheets("results").Range("C" & w)
    s = s + 1
    End If
    w= w + 1
    Loop
    End Sub
    Last edited by Leith Ross; 02-16-2014 at 10:56 PM. Reason: Added Code Tags

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Not getting correct if(and results
    By Groovicles in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 01-28-2014, 03:32 PM
  2. VLOOKUP not returning correct results
    By Lea724 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 07-22-2011, 02:38 AM
  3. Return a string from multiple checkbox results
    By dillinger in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-01-2010, 11:46 AM
  4. [SOLVED] conditional not finding correct results
    By Craig in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-01-2006, 11:40 AM
  5. [SOLVED] SQL Query not returning correct results
    By Stephen in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-20-2006, 08:25 AM

Tags for this Thread

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