Find last empty cell in column

  • Thread starter Thread starter gootroots
  • Start date Start date
G

gootroots

If "C2" contains a value then find and insert that value in the last empty
cell found in "B10:B"

If there is no value in "C2" then the code shows a megbox "No record found
in C2" the code does not execute.

I want to include the necessary code to do this with Option Explicit
declared in the module.

Much appreciate if someone could help.
 
If "C2" contains a value then find and insert that value in the last empty
cell found in "B10:B"

If there is no value in "C2" then the code shows a megbox "No record found
in C2" the code does not execute.

I want to include the necessary code to do this with Option Explicit
declared in the module.

Much appreciate if someone could help.

Hello.

Sub macro()
If [c2].Value <> "" Then
[B65536].End(xlUp).Offset(1, 0).Value = [c2].Value
End If
End Sub

Regards,

Benito
Barcelona
 
The "last empty cell" in a column would be all the way down at the bottom of
the worksheet (Row 65536 in XL2003 and earlier, Row 1048576 in XL2007)...
I'm guessing that is not what you meant. Are you looking for the blank cell
immediately after your last piece of data in Column B? Or can there be blank
cells within your data in Column B and you are looking for the last one of
those? If the latter, what did you want to do if no blanks were present
within your data?
 
Try this:

Option Explicit

Sub DataEntry()

Dim lngLastRow As Long

If IsEmpty(Range("C2")) Then
MsgBox "No record found in C2.", vbInformation
Else
lngLastRow = Cells(Rows.Count, "B").End(xlUp).Row + 1

If lngLastRow <= 10 Then
Range("B10").Value = Range("C2").Value
Else
Cells(lngLastRow, "B").Value = Range("C2").Value
End If
End If

End Sub

Hope this helps! If so click "YES" below.
 
Your code worked as hoped on its own.
Hhowever I tried to run it inside other code but it stopped when it got to
the line
lngLastRow =

not sure why it should do that
 
Back
Top