Trying to select first open or blank cell (working downwards) in column A starting from row 13 which is never blank

Sackette

New Member
Joined
Apr 13, 2015
Messages
3
Hello All
I am new to this forum and VBA codes.
I have the following macro attempting to copy the contents of a range named "blank_line" to the first empty cell in column A (ignoring the first 12 rows) of the active worksheet. I wish to start looking from row 13 which is never blank or empty. The range "blank_line" is located on another sheet of the same workbook. This macro is supposed to find the first empty cell of column A (starting at row 13) of the active sheet regardless of what the active cell is when the macro is started and paste "blank_line" in that location. The macro should end with the cell where "blank_line was pasted as being the new active cell.

Sub AddLine()
'
' AddLine Macro
'
' Keyboard Shortcut: Ctrl+a
'
Dim LastRow As Long
LastRow = ActiveSheet.Cells(Cells.Rows.Count, "A").End(xlUp).Row + 1
ActiveWorkbook.Names.Add Name:="marker", RefersToR1C1:="=" & ActiveSheet.Name & "!R" & LastRow & "C1"
ActiveWorkbook.Names("marker").Comment = ""
Application.Goto Reference:="blank_line"
Selection.Copy
Application.Goto Reference:="marker"
ActiveSheet.Paste
Application.CutCopyMode = False
ActiveWorkbook.Names("marker").Delete
End Sub

The above macro works fine until I insert a new row in the middle of the data in which case I need the macro to copy "blank_line" to the new empty row. The macro does not find this new row it simply goes to the first empty row at the bottom of the whole data field. I assume that is because it is working from the bottom of the sheet and looking up to the first blank row.

How can I get it to "look down" starting at A13?

Also, when I first started trying this I thought to name the cell where "blank_line" was to be copied to as "marker" then at the end of the macro deleting the name "marker". I'm realizing that this step is not likely required?
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Hi and welcome aboard!

Maybe something like this:

Code:
Public Sub Test()

Dim oBlanks As Range

Set oBlanks = Range("A13:A" & ActiveSheet.Range("A" & Rows.Count).End(xlUp).Row).SpecialCells(xlCellTypeBlanks)

MsgBox "First Blank: " & oBlanks.Cells(1).Address

End Sub
 
Upvote 0
Thank you Gary for the suggestion. The sample code you provided did work very well. However I was not able to figure how to incorpoarte it into my macro. As mentioned above, I did cross post this question, not knowing any better at the time, and I was provided with a solution at ExcelGuru.

Thank you for taking the time to respond to my post.
 
Upvote 0

Forum statistics

Threads
1,223,779
Messages
6,174,492
Members
452,567
Latest member
ONEIL290

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top