Counting problem in macro

  • Thread starter Thread starter A.Geeraert
  • Start date Start date
A

A.Geeraert

Can anyone help me with the following :

I have a worksheet with filled cells in columns P2 to (say) column BL2

I use this line to count the used colums, but it failed :
With ActiveSheet
lKolommen = .Range("P2:" &
..Range("P2").End(xlRight).Address).Columns.Count
End With

Why doesn't it work ?
 
Can anyone help me with the following :

I have a worksheet with filled cells in columns P2 to (say) column BL2

I use this line to count the used colums, but it failed :
With ActiveSheet
lKolommen = .Range("P2:" &
.Range("P2").End(xlRight).Address).Columns.Count
End With

Why doesn't it work ?

I don't quit know why i doesn't work, but it appears that this is what
you're trying to do:
Sub CountColoumns()
Dim lKolommen As Long
lKolommen = Range("P2").End(xlToRight).Column - Range("p2").Column
+ 1
End Sub

Per Erik
 
Closer to what you started with:


With ActiveSheet
lKolommen = .Range("P2", .Range("P2").End(xlToRight)).Columns.Count
End With
 
Back
Top