ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   macro select next blank cell in a row (https://www.excelbanter.com/excel-programming/330619-macro-select-next-blank-cell-row.html)

raph_baril

macro select next blank cell in a row
 
Hi, I'm trying to do a macro that will automaticly select the first blank
cell that will appear in a row, I have tried the following but it doesn't
select the cell but my message box will give me the right cell adress for the
empty cell.

Sub A()
Dim myCell As Range
Dim NextEmpty As Range

Set myCell = ActiveSheet.Range("c5")
Do
If myCell.Value = "" Then
Set NextEmpty = myCell
Exit Do
Else
Set myCell = myCell.Offset(0, 1)
End If
Loop

MsgBox NextEmpty.Address

End Sub




Dave Peterson[_5_]

macro select next blank cell in a row
 
Change:
MsgBox NextEmpty.Address
to
nextempty.select

But for lots of things, you don't have to select the range to work with it:

with nextempty
.value = date
.numberformat = "mm/dd/yyyy"
end with

(If I wanted the date in that cell.)

raph_baril wrote:

Hi, I'm trying to do a macro that will automaticly select the first blank
cell that will appear in a row, I have tried the following but it doesn't
select the cell but my message box will give me the right cell adress for the
empty cell.

Sub A()
Dim myCell As Range
Dim NextEmpty As Range

Set myCell = ActiveSheet.Range("c5")
Do
If myCell.Value = "" Then
Set NextEmpty = myCell
Exit Do
Else
Set myCell = myCell.Offset(0, 1)
End If
Loop

MsgBox NextEmpty.Address

End Sub


--

Dave Peterson

Doug[_13_]

macro select next blank cell in a row
 
Add NextEmpty.Select in the line before or after the MsgBox
line.


Doug


raph_baril wrote in message
...
Hi, I'm trying to do a macro that will automaticly select the first blank
cell that will appear in a row, I have tried the following but it doesn't
select the cell but my message box will give me the right cell adress for

the
empty cell.

Sub A()
Dim myCell As Range
Dim NextEmpty As Range

Set myCell = ActiveSheet.Range("c5")
Do
If myCell.Value = "" Then
Set NextEmpty = myCell
Exit Do
Else
Set myCell = myCell.Offset(0, 1)
End If
Loop

MsgBox NextEmpty.Address

End Sub







All times are GMT +1. The time now is 10:02 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com