I am pretty adept at Excel and pivot tables, but am a beginner when it comes to VBA coding. I have a pivot table that has data values in a certain range of the table, say B6 thru N100 at most. Based on slicer selections the rows that actually show visible values can be anywhere from 10 rows to 100 rows. What I am trying to do is change cell fill color on cells that I click/change, to yellow. I have scoured the internet to find the following code....
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
With Target
If .Interior.ColorIndex = 6 Then
.Interior.ColorIndex = xlColorIndexNone
Else
.Interior.ColorIndex = 6
End If
End With
End Sub
......which works great to color the cells when clicked, but I have a couple of issues I can't seem to figure out. Again, I am new to VBA.
1. How do I set the range of cells the above code applies to? Right now, it applies to the whole sheet which I don't want. At most B6 thru N100.
2. Based on slicer selections, visible rows will vary (N100 at most). Is there a way to set a dynamic range that goes to the last visible row of data?
3. Lastly, I have 13 columns of data ( B thru N). I want the above to only allow at most, one yellow highlighted cell per row (some rows may have no yellow cells). For example, if I click cell C10 and change it to yellow, if I click F10, if should change F10 to yellow, and revert C10 back to the initial fill color (no fill). Is there a way to do this?
I want to keep the ability to click a yellow cell again to revert it back to no fill color. Thank you to anyone who has any ideas and are willing to impart your knowledge and wisdom to me.
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
With Target
If .Interior.ColorIndex = 6 Then
.Interior.ColorIndex = xlColorIndexNone
Else
.Interior.ColorIndex = 6
End If
End With
End Sub
......which works great to color the cells when clicked, but I have a couple of issues I can't seem to figure out. Again, I am new to VBA.
1. How do I set the range of cells the above code applies to? Right now, it applies to the whole sheet which I don't want. At most B6 thru N100.
2. Based on slicer selections, visible rows will vary (N100 at most). Is there a way to set a dynamic range that goes to the last visible row of data?
3. Lastly, I have 13 columns of data ( B thru N). I want the above to only allow at most, one yellow highlighted cell per row (some rows may have no yellow cells). For example, if I click cell C10 and change it to yellow, if I click F10, if should change F10 to yellow, and revert C10 back to the initial fill color (no fill). Is there a way to do this?
I want to keep the ability to click a yellow cell again to revert it back to no fill color. Thank you to anyone who has any ideas and are willing to impart your knowledge and wisdom to me.