PDA

View Full Version : Find Next Column



sooty8
05-07-2010, 08:39 AM
Hi All

The Code below works OK and puts the info in the correct cell - my problem is I don't want it to go in the same cells every time I need it to find the next empty column always on row 1.


Private Sub Add_Click()
Dim iRow As Long
Dim ws As Worksheet
Set ws = Worksheets("DATA")
ws.Cells(1, 10).Value = Tb5.Value
Sheets("DATA").Select
Range("J1:K1").Select
With Selection
.HorizontalAlignment = xlCenterAcrossSelection
End With
End Sub


Regards

Sooty8

Bob Phillips
05-07-2010, 09:13 AM
Private Sub Add_Click()
Dim iRow As Long
Dim LastCol As Long
Dim ws As Worksheet
Set ws = Worksheets("DATA")
With ws

lastCol = .Cells(1, .Columns.Count).End(xlToLeft).Column)
.Cells(1, lastCol).Value = Tb5.Value
.Range("J1:K1").HorizontalAlignment = xlCenterAcrossSelection
End With
End Sub

sooty8
05-07-2010, 11:32 AM
Hi Xld

Need help getting a syntax error message on the line in Red Below.

Private Sub Add_Click()
Dim iRow As Long
Dim LastCol As Long
Dim ws As Worksheet
Set ws = Worksheets("DATA")
With ws

lastCol = .Cells(1, .Columns.Count).End(xlToLeft).Column)
.Cells(1, lastCol).Value = Tb5.Value
.Range("J1:K1").HorizontalAlignment = xlCenterAcrossSelection
End With
End Sub

Regards

Sooty8

austenr
05-07-2010, 11:44 AM
Try it w/o the ) at the end of that line.

sooty8
05-07-2010, 12:02 PM
Hi Austenr


Tried all different ways of inserting your comment in the line

lastCol = .Cells(1, .Columns.Count).End(xlToLeft).Column)

No joy I'm afraid

Sooty 8

mdmackillop
05-07-2010, 12:38 PM
lastCol = .Cells(1, .Columns.Count).End(xlToLeft).Column

Aussiebear
05-08-2010, 03:41 PM
Nothing like an errant space or two to blow you out of the water