VBA Copy Destination:= Finding First Empty cell/row

beartooth91

New Member
Joined
Dec 15, 2024
Messages
9
Office Version
  1. 365
  2. 2019
  3. 2016
Platform
  1. Windows
VBA Code:
Sub First_Empty_Row()
Worksheets("Combined").Range("B" & Rows.Count).End(xlUp).Select
End Sub

The above finds my last cell in column B with data.
Is there a way to write this, on one line and without using variables, to find the first empty cell/row?
What I'm trying to do here is copy and paste a bunch of rows from other workbooks and I'd like to use the .Copy Destination:= verbiage to do it but I need the first empty cell.
Yep, I need the .Row + 1 ending in but can't find a way to work it in that line......
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
Try something like:
VBA Code:
.Copy Destination:=Worksheets("Combined").Range("B" & Rows.Count).End(xlUp).Offset(1, 0)
 
Upvote 0
Solution
Try something like:
VBA Code:
.Copy Destination:=Worksheets("Combined").Range("B" & Rows.Count).End(xlUp).Offset(1, 0)
Not quite.... When I run it; it pastes at the next (ie. 2nd) blank cell below the data. (Leaving a blank row between the imported data sets.)
 
Upvote 0
Can you show me a screen print of the range you are trying to post to, so I can see exactly what it looks like?
And where is the data you are copying from?
Can you show me a screen print of that, as well as your entire VBA code block?

I want to try to re-create your scenario on my side so I can test it out for myself thoroughly.
 
Upvote 0
@beartooth91 what does the message box below return?

VBA Code:
Sub test()
MsgBox AscW(Worksheets("Combined").Range("B" & Rows.Count).End(xlUp)) & " " & Len(Worksheets("Combined").Range("B" & Rows.Count).End(xlUp))
End Sub
 
Upvote 0
Can you show me a screen print of the range you are trying to post to, so I can see exactly what it looks like?
And where is the data you are copying from?
Can you show me a screen print of that, as well as your entire VBA code block?

I want to try to re-create your scenario on my side so I can test it out for myself thoroughly.
My apologies.... Your code works. One of my source worksheets had a blank row at the top of the data.
 
Upvote 0
My only follow up question is there a way to write this same line, to Select......for preview/troubleshooting purposes?
 
Upvote 0
My only follow up question is there a way to write this same line, to Select......for preview/troubleshooting purposes?
In that case, I would find the row first, and then you can reference it multiple times, i.e.

VBA Code:
Dim r as Long
r = Worksheets("Combined").Range("B" & Rows.Count).End(xlUp).Offset(1, 0).Row

So then you could use this to copy it:
VBA Code:
.Destination:=Worksheets("Combined").Range("B" & r)
and
VBA Code:
Worksheets("Combined").Range("B" & r).Select
to select it.

Note that if you are on a different sheet while this code is running, you may need to explicitly select the sheet first in order to select that cell, i.e.
VBA Code:
Worksheets("Combined").Select
Range("B" & r).Select
 
Upvote 0

Forum statistics

Threads
1,224,749
Messages
6,180,727
Members
452,995
Latest member
isldboy

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