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 WriteToMaster(num, path) As Boolean
'Declare variables
Dim xlApp As Excel.Application
Dim wb As Workbook
Dim ws As Worksheet
Dim infoLoc As Integer
Set xlApp = New Excel.Application
Set wb = xlApp.Workbooks.Open("PATH OF THE DOC")
Set ws = wb.Worksheets("Sheet1")
'Loop through cells, looking for an empty one, and set that to the Num
Cells(1, 1).Select
For Each Cell In ws.UsedRange.Cells
If Cell.Value = "" Then Cell = Num
MsgBox "Checking cell " & Cell & " for value."
Next
'Save, close, and quit
wb.Save
wb.Close
xlApp.Quit
'Resets the variables
Set ws = Nothing
Set wb = Nothing
Set xlApp = Nothing
Thanks so much for any help.
If you mean the row number after the last row that is used, you can find it with this:
If you mean a row that happens to be blank with data after it… it gets more complicated.
Here’s a function I wrote which will give you the actual row number of the first row that is blank for the provided worksheet.
Usage example:
firstblankRow(thisworkbook.Sheets(1))or pass any worksheet.Edit: As ooo pointed out, this will error if there are no blank cells in your used range.