VBA - Sub select all, but add exceptions

cozzagiorgi

New Member
Joined
Jun 27, 2018
Messages
41
Hi

I have this sub wich transforms all my unchecked boxes in checked boxes (R) in column B.


Code:
Sub allewählen()
 
Dim i As Long
Dim lastrow As Long
lastrow = Cells(Rows.Count, "B").End(xlUp).Row
 
    Range("B12:B" & lastrow).Value = "R" 'R = checkedbox
 
End Sub


How can I add exceptions to this sub?

Some rows will contain the value “S” and those should not be touched by this sub.
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
You said:
R = checkedbox
What is a checkedbox??

Do you mean you have a Activex Checkbox assigned to each row and if it is checked do this?
 
Upvote 0
No, R is the value in the cell. As the Font in those Cells is Wingdings2, R equals to a symbol like a checked box. No activeX elements used.
 
Upvote 0
Since you did not say what you want to do if Column B equals R

Try this:
Replace do something with what you want to happen if column B equals R

Code:
Sub Test()
'Modified 7/9/2018 3:45 AM  EDT
Application.ScreenUpdating = False
Dim i As Long
Dim lastrow As Long
lastrow = Cells(Rows.Count, "B").End(xlUp).Row
For i = 12 To lastrow
If Cells(i, "B").Value = "R" Then
'Do something
Next
Application.ScreenUpdating = True
End Sub
 
Upvote 0
i don't think we got that right.
The code in my first post puts an "R" in all selected cells (R is looking like a checked box in Wingdings2) when I click on a button.
What I now want to do is, when I click on the button it still puts "R" in all cells, except those who contain "S" (S is looking like a crossed checkbox in Wingdings2).

Putting that "R" only in the correct boxes is all I want.
 
Upvote 0
i don't think we got that right.
The code in my first post puts an "R" in all selected cells (R is looking like a checked box in Wingdings2) when I click on a button.
What I now want to do is, when I click on the button it still puts "R" in all cells, except those who contain "S" (S is looking like a crossed checkbox in Wingdings2).

Putting that "R" only in the correct boxes is all I want.



This is beyond my knowledgebase.
I will continue to monitor this thread to see what I can learn.
 
Upvote 0
How about
Code:
Sub allewählen()
   Dim lastrow As Long
   lastrow = Cells(Rows.Count, "B").End(xlUp).Row
   With Range("B12:B" & lastrow)
      .Value = Evaluate(Replace("if(@=""S"",""S"",""R"")", "@", .Address))
   End With
End Sub
 
Upvote 0
Replace simply replaces the @ sign with .address, whilst Evaluate calculates the worksheet formula
 
Upvote 0

Forum statistics

Threads
1,223,099
Messages
6,170,108
Members
452,302
Latest member
TaMere

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