ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Get next empty Column? (https://www.excelbanter.com/excel-programming/310358-get-next-empty-column.html)

James[_30_]

Get next empty Column?
 
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



Norman Jones

Get next empty Column?
 
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.


---
Regards,
Norman



"James" wrote in message
...
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





Norman Jones

Get next 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


---
Regards,
Norman



"Norman Jones" wrote in message
...
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.


---
Regards,
Norman



"James" wrote in message
...
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







James[_30_]

Get next empty Column?
 
Thanks ALOT!! That did the trick!!


"Norman Jones" wrote in message
...
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


---
Regards,
Norman



"Norman Jones" wrote in message
...
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.


---
Regards,
Norman



"James" wrote in message
...
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










All times are GMT +1. The time now is 06:40 AM.

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