Solved

Check Boxes

Posted on 2014-02-04
6
163 Views
Last Modified: 2014-02-04
EE Pros,

I had an EE Pro build out a small macro that when you double clicked, it put a check in a box.

I've now tried to adapt it to a "row" instead of a column and cannot get it to work right.  I think it may have something to do with the "offsets".   I would appreciate some help in getting this to work correctly.

Thank you in advance,

B.
Check-Boxes.xlsm
0
Comment
Question by:Bright01
  • 3
  • 2
6 Comments
 
LVL 27

Expert Comment

by:MacroShadow
ID: 39832387
Not sure exactly how you want it adapted.

In any case the first parameter of Offset is the RowOffset and the second one is the ColumnOffset.

I assume you want something like this:
    With ActiveCell
        If .Value = "P" Then
            .Value = ""
            .Offset(4, 0).ClearContents
        ElseIf .Offset(1, 0).Value <> "" Then
            .Font.Name = "Wingdings 2"
            .Value = "P"
            .Offset(4, 0).FormulaR1C1 = ""            '"=Value"    'Value is not a defined name
        End If
    End With

Open in new window

0
 

Author Comment

by:Bright01
ID: 39832423
MacroShadow,

I changed the code to match what you sent me but it still doesn't work.

Just to be clear, when you open the sample WB/WS, and you double click on cells in Row 15, it automatically should put a "checkmark" in the box (which is capital "P" and Wingdings2).

That's what I'm trying to get working......

b.
0
 
LVL 15

Expert Comment

by:Ess Kay
ID: 39832507
Option Explicit
Sub insertCheckboxes()
 
  Dim myBox As CheckBox
  Dim myCell As Range
 
  Dim cellRange As String
  Dim cboxLabel As String
  Dim linkedColumn As String
 
  cellRange = InputBox(Prompt:="Cell Range", _
    Title:="Cell Range")
 
  linkedColumn = InputBox(Prompt:="Linked Column", _
    Title:="Linked Column")
 
  cboxLabel = InputBox(Prompt:="Checkbox Label", _
    Title:="Checkbox Label")
 
  With ActiveSheet
    For Each myCell In .Range(cellRange).Cells
      With myCell
        Set myBox = .Parent.CheckBoxes.Add(Top:=.Top, _
          Width:=.Width, Left:=.Left, Height:=.Height)
 
        With myBox
          .LinkedCell = linkedColumn & myCell.Row
          .Caption = cboxLabel
          .Name = "checkbox_" & myCell.Address(0, 0)
        End With
 
        .NumberFormat = ";;;"
      End With
 
    Next myCell
  End With
End Sub
0
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 

Author Comment

by:Bright01
ID: 39832590
Esskay,

I tried this code and unfortunately it doesn't work.  

Can you open my workbook and see what I'm trying to accomplish?  If you double click on the cells in row 15, it should automatically place a "P" that then converts to a check mark.

B.
0
 
LVL 27

Accepted Solution

by:
MacroShadow earned 500 total points
ID: 39832644
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
'Provides check button
    If Target.Row = 15 Then
        Application.ScreenUpdating = False
        With ActiveCell
            If .Value = "P" Then
                .Value = ""
            Else
                .Font.Name = "Wingdings 2"
                .Value = "P"
            End If
        End With
        'These two lines below make it a realtime update
        Cancel = True
        Application.ScreenUpdating = True
    End If
End Sub

Open in new window

0
 

Author Closing Comment

by:Bright01
ID: 39832681
Perfect!  Thank you!
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Excel Formula to split product code 5 14
VLOOKUP 6 16
Merging spreadsheets 8 31
How best to represent data in Excel? 13 15
Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

786 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question