#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27
Default Split Sheet

I have a program that dumps over 6000 lines of data into an excel
spreadsheet. I have managed to use vba to insert page breaks at various
points in the spreadsheet where header information is repeated. Now I'd like
to somehow divide this 1 sheet into multiple sheets with each page break
being a new sheet. I'd also like to have it give each sheet a specific name
by pulling a word out of cell that contains a specific word. Is this
possible with vba? Can anyone help get me started. Thanks.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,758
Default Split Sheet

This could get you started:

http://groups.google.co.uk/groups?th...apeXSPAM.c om

It actually created new workbooks, but it could be modified.

Kevin R wrote:

I have a program that dumps over 6000 lines of data into an excel
spreadsheet. I have managed to use vba to insert page breaks at various
points in the spreadsheet where header information is repeated. Now I'd like
to somehow divide this 1 sheet into multiple sheets with each page break
being a new sheet. I'd also like to have it give each sheet a specific name
by pulling a word out of cell that contains a specific word. Is this
possible with vba? Can anyone help get me started. Thanks.


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27
Default Split Sheet

It seems to have a problem when it comes to i - 1 at

ReDim Preserve HorzPBArray(1 To i - 1)

and

curWks.Rows(TopRow & ":" & HorzPBArray(i) - 1).Copy
Destination:=newWks.Range("a1")

If I change it to +1 the code seems to execute with error I just don't get
the results I want. This also seems to put each page break into a new
workbook. I want all the sheets to appear in the current workbook if
possible. Thanks.



"Dave Peterson" wrote:

This could get you started:

http://groups.google.co.uk/groups?th...apeXSPAM.c om

It actually created new workbooks, but it could be modified.

Kevin R wrote:

I have a program that dumps over 6000 lines of data into an excel
spreadsheet. I have managed to use vba to insert page breaks at various
points in the spreadsheet where header information is repeated. Now I'd like
to somehow divide this 1 sheet into multiple sheets with each page break
being a new sheet. I'd also like to have it give each sheet a specific name
by pulling a word out of cell that contains a specific word. Is this
possible with vba? Can anyone help get me started. Thanks.


--

Dave Peterson

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,758
Default Split Sheet

I put the code into a different workbook than my worksheet, and I got this
error. But it was related to the ThisWorkbook.Names.add line.

And I missed the last page using the existing routine. So I added a horizontal
page break after the last used row.

Option Explicit
Sub testme01()

Dim HorzPBArray()
Dim curWks As Worksheet
Dim newWks As Worksheet
Dim TopRow As Long
Dim i As Long

Set curWks = ActiveSheet
With curWks
.DisplayPageBreaks = False
.HPageBreaks.Add befo=.Cells.SpecialCells(xlCellTypeLastCell) _
.Offset(1, 0).EntireRow.Cells(1)

ActiveWorkbook.Names.Add Name:="hzPB", _
RefersToR1C1:="=GET.DOCUMENT(64,""" & _
ActiveSheet.Name & """)"

ActiveWorkbook.Names.Add Name:="vPB", _
RefersToR1C1:="=GET.DOCUMENT(65,""" & _
ActiveSheet.Name & """)"

i = 1
While Not IsError(Evaluate("Index(hzPB," & i & ")"))
ReDim Preserve HorzPBArray(1 To i)
HorzPBArray(i) = Evaluate("Index(hzPB," & i & ")")
i = i + 1
Wend

ReDim Preserve HorzPBArray(1 To i - 1)

TopRow = 1
For i = LBound(HorzPBArray) To UBound(HorzPBArray)
Set newWks = Worksheets.Add
curWks.Rows(TopRow & ":" & HorzPBArray(i) - 1).Copy _
Destination:=newWks.Range("a1")
TopRow = HorzPBArray(i)
Next i

End Sub

From my first post:
It actually created new workbooks, but it could be modified.


This one adds a new worksheet per "page".

Kevin R wrote:

It seems to have a problem when it comes to i - 1 at

ReDim Preserve HorzPBArray(1 To i - 1)

and

curWks.Rows(TopRow & ":" & HorzPBArray(i) - 1).Copy
Destination:=newWks.Range("a1")

If I change it to +1 the code seems to execute with error I just don't get
the results I want. This also seems to put each page break into a new
workbook. I want all the sheets to appear in the current workbook if
possible. Thanks.

"Dave Peterson" wrote:

This could get you started:

http://groups.google.co.uk/groups?th...apeXSPAM.c om

It actually created new workbooks, but it could be modified.

Kevin R wrote:

I have a program that dumps over 6000 lines of data into an excel
spreadsheet. I have managed to use vba to insert page breaks at various
points in the spreadsheet where header information is repeated. Now I'd like
to somehow divide this 1 sheet into multiple sheets with each page break
being a new sheet. I'd also like to have it give each sheet a specific name
by pulling a word out of cell that contains a specific word. Is this
possible with vba? Can anyone help get me started. Thanks.


--

Dave Peterson


--

Dave Peterson
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27
Default Split Sheet

This worked absolutely perfectly, just like I had asked. Thanks so much.
The only issue I hadn't considered is that it creates a new sheet for every
horizontal page break, not just the ones I inserted. Is there anyway to tell
it to distinguish between a hard page break (one that I forced with vba)
versus all page breaks? Thanks again for the help.

"Dave Peterson" wrote:

I put the code into a different workbook than my worksheet, and I got this
error. But it was related to the ThisWorkbook.Names.add line.

And I missed the last page using the existing routine. So I added a horizontal
page break after the last used row.

Option Explicit
Sub testme01()

Dim HorzPBArray()
Dim curWks As Worksheet
Dim newWks As Worksheet
Dim TopRow As Long
Dim i As Long

Set curWks = ActiveSheet
With curWks
.DisplayPageBreaks = False
.HPageBreaks.Add befo=.Cells.SpecialCells(xlCellTypeLastCell) _
.Offset(1, 0).EntireRow.Cells(1)

ActiveWorkbook.Names.Add Name:="hzPB", _
RefersToR1C1:="=GET.DOCUMENT(64,""" & _
ActiveSheet.Name & """)"

ActiveWorkbook.Names.Add Name:="vPB", _
RefersToR1C1:="=GET.DOCUMENT(65,""" & _
ActiveSheet.Name & """)"

i = 1
While Not IsError(Evaluate("Index(hzPB," & i & ")"))
ReDim Preserve HorzPBArray(1 To i)
HorzPBArray(i) = Evaluate("Index(hzPB," & i & ")")
i = i + 1
Wend

ReDim Preserve HorzPBArray(1 To i - 1)

TopRow = 1
For i = LBound(HorzPBArray) To UBound(HorzPBArray)
Set newWks = Worksheets.Add
curWks.Rows(TopRow & ":" & HorzPBArray(i) - 1).Copy _
Destination:=newWks.Range("a1")
TopRow = HorzPBArray(i)
Next i

End Sub

From my first post:
It actually created new workbooks, but it could be modified.


This one adds a new worksheet per "page".

Kevin R wrote:

It seems to have a problem when it comes to i - 1 at

ReDim Preserve HorzPBArray(1 To i - 1)

and

curWks.Rows(TopRow & ":" & HorzPBArray(i) - 1).Copy
Destination:=newWks.Range("a1")

If I change it to +1 the code seems to execute with error I just don't get
the results I want. This also seems to put each page break into a new
workbook. I want all the sheets to appear in the current workbook if
possible. Thanks.

"Dave Peterson" wrote:

This could get you started:

http://groups.google.co.uk/groups?th...apeXSPAM.c om

It actually created new workbooks, but it could be modified.

Kevin R wrote:

I have a program that dumps over 6000 lines of data into an excel
spreadsheet. I have managed to use vba to insert page breaks at various
points in the spreadsheet where header information is repeated. Now I'd like
to somehow divide this 1 sheet into multiple sheets with each page break
being a new sheet. I'd also like to have it give each sheet a specific name
by pulling a word out of cell that contains a specific word. Is this
possible with vba? Can anyone help get me started. Thanks.

--

Dave Peterson


--

Dave Peterson



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,758
Default Split Sheet

Just the manual page breaks?

Option Explicit
Sub testme01()

Dim HorzPBArray()
Dim curWks As Worksheet
Dim newWks As Worksheet
Dim TopRow As Long
Dim i As Long

Set curWks = ActiveSheet
With curWks
.DisplayPageBreaks = False
.HPageBreaks.Add befo=.Cells.SpecialCells(xlCellTypeLastCell) _
.Offset(1, 0).EntireRow.Cells(1)
End With

ActiveWorkbook.Names.Add Name:="hzPB", _
RefersToR1C1:="=GET.DOCUMENT(64,""" & _
ActiveSheet.Name & """)"

ActiveWorkbook.Names.Add Name:="vPB", _
RefersToR1C1:="=GET.DOCUMENT(65,""" & _
ActiveSheet.Name & """)"

i = 1
While Not IsError(Evaluate("Index(hzPB," & i & ")"))
ReDim Preserve HorzPBArray(1 To i)
HorzPBArray(i) = Evaluate("Index(hzPB," & i & ")")
i = i + 1
Wend

ReDim Preserve HorzPBArray(1 To i - 1)

TopRow = 1
For i = LBound(HorzPBArray) To UBound(HorzPBArray)
If curWks.Rows(HorzPBArray(i)).PageBreak = xlPageBreakManual Then
Set newWks = Worksheets.Add
curWks.Rows(TopRow & ":" & HorzPBArray(i) - 1).Copy _
Destination:=newWks.Range("a1")
TopRow = HorzPBArray(i)
End If
Next i

End Sub

There was an error in my earlier post. I dropped an "end with", but it sounds
like you got it working ok.

My question. Are you breaking up a list based on a certain column. When it
changes, then create a new sheet?

If you are, you may want to use a different technique than manually inserting
page breaks.


Maybe you can steal some code from Debra Dalgleish's site:
http://www.contextures.com/excelfiles.html

Create New Sheets from Filtered List -- uses an Advanced Filter to create
separate sheet of orders for each sales rep visible in a filtered list; macro
automates the filter. AdvFilterRepFiltered.xls 35 kb

Update Sheets from Master -- uses an Advanced Filter to send data from
Master sheet to individual worksheets -- replaces old data with current.
AdvFilterCity.xls 55 kb

Kevin R wrote:

This worked absolutely perfectly, just like I had asked. Thanks so much.
The only issue I hadn't considered is that it creates a new sheet for every
horizontal page break, not just the ones I inserted. Is there anyway to tell
it to distinguish between a hard page break (one that I forced with vba)
versus all page breaks? Thanks again for the help.

"Dave Peterson" wrote:

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Split a sheet in Excel birmel Excel Worksheet Functions 0 July 30th 09 08:15 AM
split sheet into tabs in EXCEL Joe Excel Discussion (Misc queries) 12 June 2nd 09 05:53 PM
Split text file into Excel sheet and separate the final results intoa new sheet Luciano Paulino da Silva Excel Worksheet Functions 8 April 18th 09 02:00 AM
spread sheet how do you split a cell The Rose Excel Discussion (Misc queries) 4 June 24th 07 03:22 PM
Split up summary sheet Compass Rose Excel Worksheet Functions 2 March 8th 07 07:08 AM


All times are GMT +1. The time now is 10:11 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"