Excel VBA - Selecting the next empty cell in a row

November 2016

Visual Basic Application or VBA , when used in Microsoft Excel, is an efficient tool, as repetitive jobs can be automated with the help of this application. The users can write custom VBA code to meet their programming needs. Through interesting properties like offset, one can operate across different cells in Excel. Operations like selecting the next empty cell in a row can be automatically done, but only when this property is chosen in VBA .

Issue


I am using Excel 2002
The code below works fine except I want to select the next empty cell to the right in the row each time the same player's score is entered.
As it reads now, it just overwrites the previous entry.



Sheets("Classic").Select      
ActiveSheet.Unprotect      

Range("B1").Select      
Do Until ActiveCell.Value = Player.Value      
ActiveCell.Offset(1, 0).Select      
Loop      
ActiveCell.Value = Player.Value      
Activecell.offset(0,4).value=Score.value      

ActiveSheet.Protect      

GameNumber.Value = ""      
Player.Value = ""      
Score.Value = "" 

Solution


TRY THIS:

ActiveCell.Value = Player.Value      
Activecell.offset(0,4).value=Score.value      

'find last used cell on the row to the right      
ActiveCell.End(xlToRight).Select      

'move one cell to the right from the last used cell      
ActiveCell.Offset(0, 1).Select 

Note


Thanks to rizvisa1 for this tip on the forum.

Related :

This document entitled « Excel VBA - Selecting the next empty cell in a row » from CCM (ccm.net) is made available under the Creative Commons license. You can copy, modify copies of this page, under the conditions stipulated by the license, as this note appears clearly.