• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Combine 2 Macros

Dokat

Member
Hi,

How can i combine two below macros into one? One of the macros sort the data and the other is for checkbox property.

First Macro

Code:
Option Explicit
Sub testme()
Dim ThisCBX As CheckBox
Dim CBX As CheckBox
Set ThisCBX = ActiveSheet.CheckBoxes(Application.Caller)
If ThisCBX.Value = xlOn Then
For Each CBX In ActiveSheet.CheckBoxes
If CBX.Name = ThisCBX.Name Then
'do nothing
Else
CBX.Value = xlOff
End If
Next CBX
End If
End Sub
Second Macro

Code:
Sub CheckBox3()
Application.ScreenUpdating = False
'Sub sbSortDataInExcelInDescendingOrder()
Dim strDataRange, strkeyRange As String
strDataRange = "C2:F13"
strkeyRange = "d3:d13"
With Sheets("Sheet2").Sort
.SortFields.Clear
.SortFields.Add _
Key:=Range(strkeyRange), _
SortOn:=xlSortOnValues, _
Order:=xlDescending, _
DataOption:=xlSortNormal
.SetRange Range(strDataRange)
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Application.ScreenUpdating = True
End Sub
 
Code:
Sub CheckBox3()

'Setup Checkboxes
Dim ThisCBX As CheckBox
Dim CBX As CheckBox

Set ThisCBX = ActiveSheet.CheckBoxes(Application.Caller)

If ThisCBX.Value = xlOn Then
    For Each CBX In ActiveSheet.CheckBoxes
        If CBX.Name <> ThisCBX.Name Then CBX.Value = xlOff
    Next CBX
End If

'sbSortDataInExcelInDescendingOrder()
Dim strDataRange, strkeyRange As String
strDataRange = "C2:F13"
strkeyRange = "e3:e13"
With Sheets("Sheet2").Sort
    .SortFields.Clear
    .SortFields.Add _
    Key:=Range(strkeyRange), _
    SortOn:=xlSortOnValues, _
    Order:=xlDescending, _
    DataOption:=xlSortNormal
    .SetRange Range(strDataRange)
    .Header = xlYes
    .MatchCase = False
    .Orientation = xlTopToBottom
    .SortMethod = xlPinYin
    .Apply
End With
End Sub
 
Back
Top