• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Enter text in last cell +1 of a list - Macros

Dee

Member
Dear experts, i am trying add a text called "NULL" in the last cell next to the list in a row.

EX: if list starts in A1 and ends in C1 then the word "NULL" should come in D1.


Below is the code i wrote somehow it is neither working not showing any errors. Can any one of you help me on this pls...


Sub inputinLastCell()

Dim lastcell As String

lastcell = range("A1").End(xlToRight).Select + 1

If lastcell = 0 Then

lastcell = "NULL"

Else

End If

End Sub
 
Dee

What about this :

[pre]
Code:
Sub inputinLastCell()
If Range("A1").End(xlToRight).Offset(0, 1).Value = 0 Then Range("A1").End(xlToRight).Offset(0, 1).Value = "NULL"
End Sub
[/pre]

End(xlToRight) will take you to the last cell with any data and contiguous with A1,

so by default the next cell is blank
 
Hi, Dee!


In the case you'd need to apply this method to a row that contains blank cells (i.e. with non-blank cells non contiguous), you can do this:


-----

[pre]
Code:
Sub inputinLastCell()
ActiveCell.EntireRow.Select
Cells(ActiveCell.Row, Selection.Columns.Count).End(xlToLeft).Offset(0, 1).Select
ActiveCell.Value = "NULL"
End Sub
[/pre]
-----


It works with any Excel version (256/16384 cols) retrieving last column number from whole row selection, going to the very last cell in row -not just until first blank cell-, and then returning to first blank cell.


Regards!
 
Back
Top