Simple question - Checkboxes - paint last row when enabled

Ryokan

New Member
Joined
Jul 8, 2011
Messages
12
I have a checkbox in a userform, i want that when the chexkbox is enabled, paint (yellow) the last filled row.

Thank you. :)
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
Try in the userform's code module

Code:
Private Sub CheckBox1_Click()
Dim LR As Long
LR = Cells.Find(What:="*", SearchDirection:=xlPrevious, SearchOrder:=xlByRows).Row
Rows(LR).Interior.ColorIndex = IIf(CheckBox1.Value = True, 6, xlNone)
End Sub
 
Upvote 0
Nice VoG. Is working so-so, the worksheet name is "Hoja de Vida Anillos-Cilindros", i need this to work in that specific worksheet so i think that something is missing.

Thank you. :)
 
Upvote 0
Try

Code:
Private Sub CheckBox1_Click()
Dim LR As Long
With Sheets("Hoja de Vida Anillos-Cilindros")
    LR = .Cells.Find(What:="*", SearchDirection:=xlPrevious, SearchOrder:=xlByRows).Row
    .Rows(LR).Interior.ColorIndex = IIf(CheckBox1.Value = True, 6, xlNone)
End With
End Sub
 
Upvote 0
Great :D... one last question if i want that when the user click again (unable the checkbox), get those rows with no fill... what do i need to add (to the code)??
 
Upvote 0
Theres a little problem,
when i click the 1st time (Enabled) > paints the row, good
click the 2nd time (unabled)> nothing happen
click again (enabled again) > paint the row, two rows down from the 1st paint

Apparently it goes 1 row down every time that i click on the checkbox
 
Upvote 0
It doesn't do that for me. I tested with row 9 as the last row. I ticked the checkbox and row 9 was highlighted, unticked and row 9 was not highlighted. Over and over, no change in the row being highlighted.
 
Upvote 0
Youre right the problem is that i took out the * in the What Section

Private Sub CheckUltMaq_Click()
Dim LR As Long
With Sheets("Hoja de Vida Anillos-Cilindros")
LR = .Cells.Find(What:="", SearchDirection:=xlPrevious, SearchOrder:=xlByRows).Row
.Rows(LR).Interior.ColorIndex = IIf(CheckUltMaq.Value = True, 6, xlNone)
End With
End Sub

The thing is i maded a mistake, i need to paint the first empty row in the table (not the last filled row), because the data is not yet introduced when the click in the checkbox is maded. But youre right with the * work properly. how can i make this work ??

Thank you.
 
Upvote 0
Try

Code:
Private Sub CheckUltMaq_Click()
Dim LR As Long
With Sheets("Hoja de Vida Anillos-Cilindros")
    LR = .Cells.Find(What:="*", SearchDirection:=xlPrevious, SearchOrder:=xlByRows).Row + 1
    .Rows(LR).Interior.ColorIndex = IIf(CheckUltMaq.Value = True, 6, xlNone)
End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,606
Messages
6,179,862
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