Changing multiple cells based on single selection

Rasm

Well-known Member
Joined
Feb 9, 2011
Messages
505
I have a large sheet - in column 3 I have a cell value that toggle between False/True - This indicates if that row is ignored or not when I do calculations. However I want to be able to select mutiple rows - then toggle the value(s) in column 3 for all rows selected. I left in the other part of this event - as Row= 4 - sorts the data by whatever column clicked - so I do a sort - then make a selection of a bunch of rows to "Toggle" - sort again - make more "Toggle" selections and so on.

The code cannot reside in the sheet section as this is eventually an add-in

The code in red is what I am lookin to change(optimize)

ThisWorkBook
Code:
Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
    Select Case Target.Row
        Case 1
            If Target.Column = 4 Then Call ComboBoxX_Click
        Case 4
            If IsEmpty(Target.Value) Then Exit Sub
            Static MySortType As Integer
            If MySortType = 0 Then
                MySortType = xlAscending
            ElseIf MySortType = xlAscending Then
                MySortType = xlDescending
            ElseIf MySortType = xlDescending Then
                MySortType = xlAscending
            End If
            Target.CurrentRegion.Offset(1).Sort key1:=Target, order1:=MySortType, Header:=xlYes
    End Select
    [COLOR=red]Select Case Target.Column
        Case 3
            If Target.Row >= 5 And ActiveSheet.Cells(4, Target.Column).Value = "Ignore" Then
                With ActiveCell
                    If .Value = "True" Then
                            .Value = "False"
                            .Interior.Color = &HFFFFFF        'White
                        Else
                            .Value = "True"
                            .Interior.Color = &H80FFFF       'Yellow
                    End If
                End With
            End If
    End Select
[/COLOR]End Sub


PS I really wanted column 3 to be a checkbox - but after having inserted Checkboxes for multiple thousand rows - Excel starts to crawl - so I gave up on that idea.
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
I have tried to use

Selection.Address

But when Len(Selection.Address) reaches 251 - it quits - no error no nothing - I tried this as an alternative to the event code above above - :( -
 
Upvote 0
Does anybody knows if I can simply save the Selection.Address in a variable - next change to selection back to nothing - then continue selection - If > 240 then add it to my save variable. So can I potentially use this to make slections that can be very very long as I keep the accumulated selection in the save variable - So when the user is done with the selction - I can have a button to press to process the selection



Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
If Len(Selection.Address) > 240 Then
MsgBox "How to deal with this"
End If
end sub
 
Upvote 0

Forum statistics

Threads
1,224,603
Messages
6,179,849
Members
452,948
Latest member
UsmanAli786

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top