Finding first blank row, then writing to it

后端 未结 8 1881
小鲜肉
小鲜肉 2020-12-02 00:30

I need to find the first blank row in a workbook and write information to (row, 1) and (row, 2). I think I\'m currently pretty stuck...

Function WriteToMaste         


        
8条回答
  •  温柔的废话
    2020-12-02 00:46

    I know this is an older thread however I needed to write a function that returned the first blank row WITHIN a range. All of the code I found online actually searches the entire row (even the cells outside of the range) for a blank row. Data in ranges outside the search range was triggering a used row. This seemed to me to be a simple solution:

    Function FirstBlankRow(ByVal rngToSearch As Range) As Long
       Dim R As Range
       Dim C As Range
       Dim RowIsBlank As Boolean
    
       For Each R In rngToSearch.Rows
          RowIsBlank = True
          For Each C In R.Cells
             If IsEmpty(C.Value) = False Then RowIsBlank = False
          Next C
          If RowIsBlank Then
             FirstBlankRow = R.Row
             Exit For
          End If
       Next R
    End Function
    

提交回复
热议问题