cthallofamer
cthallofamer

Reputation: 141

Excel VBA: How to change value of cell in last used column?

I am new to VBA and am trying to locate the last used column (changes monthly) and change the second row cell in that column to "Apple." The values in the last used column start from row 5, but I need to change row 2. Can anyone help? This the code I have come up with, I understand it's flawed:

    Sub NameCell()
.Cells(5, Columns.Count).End(xlToLeft).Column.Select
.FormulaR3C1 = "Apple"
End Sub

Upvotes: 0

Views: 445

Answers (1)

Scott Craner
Scott Craner

Reputation: 152525

Sub NameCell()
With ActiveSheet    
    .Cells(2,.Cells(5, .Columns.Count).End(xlToLeft).Column).Value = "Apple"
End With
End Sub

Upvotes: 1

Related Questions