auto freeze panes procedure

P

PBcorn

attempting to write code to set up a split and freeze panes on several
worksheets, centreing the split on the first cell with a number value ( can
be 0, but not blank, not a date (incl 2004,2005, jan-08 etc). so that the row
and column headers are static outside the split area. Area should look like
this, filled with numeric data:

jan-08 feb-08 mar-08
a b
b b
c d
d d

the problem is that typename, isnumric and isnull all fail to exclude (blank
or date or string) which is what i need to do to find the first cell with
data in it which is where the split is centered.
 
T

The Code Cage Team

Does this do what you need?

Sub split_at_Number()
Dim MyCell As Range
For Each MyCell In ActiveSheet.UsedRange
If MyCell <> "" And IsNumeric(MyCell) Then
MyCell.Offset(0, 1).Select
ActiveWindow.FreezePanes = True
'With ActiveWindow 'these 4 lines will install a split at th
frozen cell
'.SplitColumn = 0
'.SplitRow = 0
'End With
End If
Next

End Su
*-Post posted before response, posts merged!*
There was a small typo in the code!

Sub split_at_Number()
Dim MyCell As Range
For Each MyCell In ActiveSheet.UsedRange
If MyCell <> "" And IsNumeric(MyCell) Then
MyCell.Offset(0, 1).Select
ActiveWindow.FreezePanes = True
'With ActiveWindow 'these 4 lines will install a split at the froze
cell
'.SplitColumn = 0
'.SplitRow = 0
'End With
End If
Next

End Su

--
The Code Cage Tea

Regards,
The Code Cage Team
www.thecodecage.co
 
P

PBcorn

Thanks but i ended up using:

If Not TypeName(curcell.Value) = "Empty" _
And Not TypeName(curcell.Value) = "String" _
And Not TypeName(curcell.Value) = "Date" _
And Not curcell.Value = 2002 _
And Not curcell.Value = 2003 _
And Not curcell.Value = 2004 _
And Not curcell.Value = 2005 _
And Not curcell.Value = 2006 _
And Not curcell.Value = 2007 _
And Not curcell.Value = 2008 _
And Not curcell.Value = 2009 Then

to exclude all label cells and the blanks above the labels. However i have
now found that some of the sheet's data contains blank cells. Need to modify
logic to only exclude blank cells above the column headers. There are also
some sheets where the macro puts the split in the middle of the data, which i
can't figure out a reason for, as all the data cells are filled with numbers.
 

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

Top