I am trying to make a macro that on the press of a button highlights a random row in a selection. I have the following code (which is based on an answer generously provided by @gtwebb to @Kyle Snell):
Sub SelectRandom()
Dim mrg As Worksheet
Set mrg = ActiveWorkbook.Sheets("Merged")
Dim PopulationSelect As Range
Set PopulationSelect = mrg.Range("A" & Rows.Count).End(xlUp)
RandSample = Int(PopulationSelect.Rows.Count * Rnd + 1)
PopulationSelect.Rows(RandSample).EntireRow.Interior.Color = RGB(255, 255, 153)
End Sub
Now on the sheet I have a header that takes up Range("A1:L5") so I'd need the code to randomly select and highlight a row from any of the rows below the header that contain data. How would I go about doing it? The code only selects and highlights the last row containing data at the moment.
Aucun commentaire:
Enregistrer un commentaire