I have this function that will go through BG2 and :BG17 and randomly display the value of a cell within that range in AS25.
But, sometimes some of these cells within the range have no value, and it displays nothing in AS25.
How can I prevent that, by skipping the cells without value?
Sub RandomFromRange()
Dim ws As Worksheet
Set ws = Worksheets("Main")
Application.ScreenUpdating = False
ws.Range("AS25") = WorksheetFunction.Index(Range("BG2:BG17"), WorksheetFunction.RandBetween(1, ws.Range("BG2:BG17").Rows.Count), WorksheetFunction.RandBetween(1, ws.Range("BG2:BG17").Columns.Count))
Range("AY1").Select
Application.ScreenUpdating = True
End Sub
But, sometimes some of these cells within the range have no value, and it displays nothing in AS25.
How can I prevent that, by skipping the cells without value?
Sub RandomFromRange()
Dim ws As Worksheet
Set ws = Worksheets("Main")
Application.ScreenUpdating = False
ws.Range("AS25") = WorksheetFunction.Index(Range("BG2:BG17"), WorksheetFunction.RandBetween(1, ws.Range("BG2:BG17").Rows.Count), WorksheetFunction.RandBetween(1, ws.Range("BG2:BG17").Columns.Count))
Range("AY1").Select
Application.ScreenUpdating = True
End Sub