Get next empty Column?

  • Thread starter Thread starter James
  • Start date Start date
J

James

I want the button to copy from one sheet and each time I'd like it to place
the numbers in the next available column

Do I need to loop and check for emptiness?

Thanks
 
Hi James,

To set a variable Rng to the first empty cell in row 1 on sheet2, try:

Dim Rng As Range
Const rw As Long = 1 '<<====== CHANGE
If IsEmpty(Cells(rw, 1)) Then
Set Rng = Cells(rw, 1)
Else
Set Rng = Cells(rw, Columns.Count). _
End(xlToLeft)(1, 2)
End If
MsgBox Rng.Address


Change the rw value to reflect the row that you use to test for an empty
column.
 
Hi James,

I omitted to qualify the code to refer to Sheet2:

Dim Rng As Range
Const rw As Long = 1 '<<====== CHANGE

With Sheets("Sheet2") '<<====== CHANGE
If IsEmpty(.Cells(rw, 1)) Then
Set Rng = .Cells(rw, 1)
Else
Set Rng = .Cells(rw, Columns.Count). _
End(xlToLeft)(1, 2)
End If
End With
MsgBox Rng.Address
 
Thanks ALOT!! That did the trick!!


Norman Jones said:
Hi James,

I omitted to qualify the code to refer to Sheet2:

Dim Rng As Range
Const rw As Long = 1 '<<====== CHANGE

With Sheets("Sheet2") '<<====== CHANGE
If IsEmpty(.Cells(rw, 1)) Then
Set Rng = .Cells(rw, 1)
Else
Set Rng = .Cells(rw, Columns.Count). _
End(xlToLeft)(1, 2)
End If
End With
MsgBox Rng.Address
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top