Home > Software engineering >  Selected random rows and do stuff - select multiple row on range
Selected random rows and do stuff - select multiple row on range

Time:11-21

It seems to be fairly simple but I'm struggling...
I have this simple code to select entire row from a black range of cells, which is totally random, base on the current data.
Because the cells F5 F7 F9 F13 are empty, it selects the entire row.
So, I wish to change the value from column 1 [A] and 8 [H] to "Estoque", coloured in light blue.
And I'm stuck on that. Any help, please?

 On Error Resume Next
 Columns("H:H").SpecialCells(xlCellTypeBlanks).EntireRow.Select

enter image description here

CodePudding user response:

A SpecialCells-Intersect Combination

Option Explicit

Sub Estoque()
    
    Dim rg As Range
    
    On Error Resume Next
        Set rg = Intersect(Range("A:A,H:H"), _
            Columns("H:H").SpecialCells(xlCellTypeBlanks).EntireRow)
    On Error GoTo 0
    
    If rg Is Nothing Then
        MsgBox "Nope!", vbCritical
        'Exit Sub
    Else
        rg.Value = "Estoque"
        MsgBox "Estoque!", vbInformation
    End If
    
End Sub
  • Related