VBA: Code to find first empty cell in column A

Puppies72

Board Regular
Joined
Mar 29, 2010
Messages
211
Hi all,

I'm struggling my way through a macro with help from you all and am bringing in data from several sheets into a single sheet - what I need to do is to copy certain ranges (which I know how to select and do now) but then I need to paste it beneath the last active cell in column A which can vary.

So for instance if the first part of my macro copies in 450 entries into column A and the next part selects 100 entries it needs to paste those starting from A451 (the next empty cell).

The number of entries copied in will vary every time which is why I need a flexible way to do this.

As always help gratefuly appreciated!
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Code:
Range("A" & Rows.Count).End(xlup).Offset(1).Row
Cells(Rows.Count,1).End(xlup).Offset(1).Row
UsedRange.Rows.Count

How would I make this code select the the first blank cell in column A? Where would the .Select go?
 
Upvote 0
that doesn't sound so complex...
Code:
Dim LastRow as Long
LastRow = Sheets("Sheet1").Cells(Rows.Count,1).End(xlup).Offset(1).Row

Sheets("Sheet2").Range("A1").Copy Sheets("Sheet1").Cells(LastRow,1)


I've been trying to use this code, but my skills with vba are lacking. What I'm trying to do is to use a "enter" button connected to a macro. The idea is I enter information into "a4","b4","c4","d4","e4" in my "Entry" worksheet. The information in "c4" and "d4" indicate what columns to use in my worksheet "Data", so if "c4"="restaurant" then "a4".copy into next blank in Column "e" in "Data", "b4".copy into next blank in Column "f" in "Data", "e4".copy into next blank in Column "g" in "Data, and if "d4"="Cash" then "a4".copy into next blank in Column "bb" in "Data", "b4".copy into next blank in Column "bc" in "Data"

"c4" and "d4" have several options, so I'll need a code that is or(if("d4"=This, then "copy to here"),[next if statement]).

That's the best I can do to describe it. Can anyone help? I can provide more information if needed!

Thanks,

Dylan
 
Upvote 0
Hi,

I`m using this code to fill in the next empty rows with current time :

Sub CommandButton1_Click()

With Sheets("Sheet2")

NextRow = .Range("A" & Rows.Count).End(xlUp).Row + 1

.Range("A" & NextRow) = Now()

End With

End Sub


Using the code above the fillings will start from cell(A2) and it wont stop in certain cell.
The problem I have is that I need to start from certain row and apply it ony to certain range only.

Somebody can help me with this?

Thanks in advance






there are numerous ways of determining the last row or first blank row...

Range("A" & Rows.Count).End(xlup).Offset(1).Row
Cells(Rows.Count,1).End(xlup).Offset(1).Row
UsedRange.Rows.Count
 
Upvote 0
Hi,

I`m using this code to fill in the next empty rows with current time :

Sub CommandButton1_Click()

With Sheets("Sheet2")

NextRow = .Range("A" & Rows.Count).End(xlUp).Row + 1

.Range("A" & NextRow) = Now()

End With

End Sub


Using the code above the fillings will start from cell(A2) and it wont stop in certain cell.
The problem I have is that I need to start from certain row and apply it ony to certain range only.

Somebody can help me with this?

Thanks in advance


So once a certain number of cells are populated, what do you want the code to do?

By the way, the code you posted could be simplified to:

Code:
Sub CommandButton1_Click()
Sheets("Sheet2").Range("A" & Rows.Count).End(xlUp).Offset(1) = Now()
End Sub
 
Upvote 0
Thank You.

I am going to record start and stop times for certain resources and activities. So I will have to put them in certain cells. At the end I will get the duration of each activities done by each resources.

This is the solution I have for now :

CODE :

Sub Test()

Dim cell As Range

Dim i As Long

With Worksheets("Sheet2")
For Each cell In .Range("C5:C10")
If cell.Value = "" Then
i = cell.Row
.Range("C" & i).Value = Now()
Exit For
End If

Next cell
End With

End Sub

Should you have better solution please let me know.

So once a certain number of cells are populated, what do you want the code to do?

By the way, the code you posted could be simplified to:

Code:
Sub CommandButton1_Click()
Sheets("Sheet2").Range("A" & Rows.Count).End(xlUp).Offset(1) = Now()
End Sub
 
Upvote 0
You could replace your existing code with a single line...
Code:
Sheets("Sheet2").Range("C5:C10").SpecialCells(xlCellTypeBlanks) = Now()
 
Upvote 0
Thank You, but the code fills range C5:C10 at the same time simultaneously. I`m using a command button and I need only to fill one cell every time I press the command button.


You could replace your existing code with a single line...
Code:
Sheets("Sheet2").Range("C5:C10").SpecialCells(xlCellTypeBlanks) = Now()
 
Upvote 0
Thank You, but the code fills range C5:C10 at the same time simultaneously. I`m using a command button and I need only to fill one cell every time I press the command button.

My code does exactly the same as your code, just more efficiently. Please explain exactly what you want the code to do.
 
Upvote 0

Forum statistics

Threads
1,221,508
Messages
6,160,222
Members
451,631
Latest member
coffiajoseph

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