LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Divide rows equally & extract first & last of each block...Possible?

Sorry I meant to add there is 7 worksheets of addresses each sheet is a
delivery run.

<'Change this to the sheet CODE NAME of the sheet that contains
Addresses.
Set wsAddresses = Sheet3

This may work for 1 sheet but can I reference just the worksheet in use?

Cheers

Mark


On 10/09/08 4:54 PM, in article
,
" wrote:

Hi Major,
this might work...It will require some modifications.
Copy this into a module in the workbook you are using.
I suppose I could have done this more concisely but this is more
reusable and easier to understand.
Regards
Bernie Russell
-----------------------------------------------------------
Option Explicit
Public wsAddresses As Worksheet
Public col As Range

Public Function FirstRow() As Range
'Dim StartCell As Range
'Set StartCell = Intersect(ws.Rows(1), col)
'
'If StartCell < "" Then
' Set FirstRow = StartCell
'Else
' Set FirstRow = StartCell.End(xlDown)
'End If

'OR use this:
Set FirstRow = wsAddresses.Range("A2") 'Substitute address of first
cell containing an address

End Function

Public Function LastRow() As Range
Dim StartCell As Range
Set StartCell = Intersect(wsAddresses.Rows(65536), col)

If StartCell < "" Then
Set LastRow = StartCell
Else
Set LastRow = StartCell.End(xlUp)
End If

End Function

Public Function RangeWithAddresses() As Range
Set RangeWithAddresses = Range(FirstRow, LastRow)
End Function

Public Function CountOfRows() As Integer
CountOfRows = RangeWithAddresses.Rows.Count
End Function

Sub CreatePostieShares()

Dim iPosties As Integer
Dim iCount As Double
Dim rPosties As Range
Dim c As Range
Dim iStart As Integer
Dim iFinish As Integer
Dim iAddressShare As Integer
Dim rAddressShare As Range
Dim wsPostieShare As Worksheet
Dim wsPosties As Worksheet
With Application
.ScreenUpdating = False
.Calculation = xlCalculationManual

'Change this to the sheet CODE NAME of the sheet that contains
Addresses.
Set wsAddresses = Sheet3

'Change this to the column number that contains the addresses
Set col = wsAddresses.Columns(1)
'Create a sheet and place the available posties in the first column
starting at cell A2, add as many as
'you require. Change this to the SHEET CODE NAME of the new sheet.
Set wsPosties = Sheet4
With wsPosties
Set rPosties = .Range(.Range("A2"), .Range("A65536").End(xlUp))
End With

iCount = CountOfRows
iAddressShare = CInt(iCount / rPosties.Cells.Count)
iStart = 1
iFinish = iAddressShare

For Each c In rPosties

With wsAddresses

Set rAddressShare
= .Range(.Columns(1).Cells(iStart), .Columns(1).Cells(iFinish)).EntireRow


If SheetExists(c.Value) = False Then
Set wsPostieShare = ThisWorkbook.Worksheets.Add(, wsPosties)
Else
Set wsPostieShare = Worksheets(c.Value)
End If

With wsPostieShare
.UsedRange.Clear
rAddressShare.Copy .Cells(1) 'or whatever cell you want it to
go in
End With

iStart = iFinish + 1
iFinish = iStart + iAddressShare

End With 'wsAddresses

Next c

.ScreenUpdating = True
.Calculation = xlCalculationAutomatic

End With 'Application

End Sub

Public Function SheetExists(WorksheetName As String) As Boolean
On Error Resume Next
Dim wsTemp As Worksheet
Set wsTemp = Worksheets(WorksheetName)

If Err.Number = 0 Then
SheetExists = True
Else
SheetExists = False
End If

End Function




 
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
divide and copy rows glenn[_3_] Excel Programming 1 September 28th 07 09:24 PM
divide records equally among multiple employees Martin Leffler Excel Worksheet Functions 5 August 28th 06 11:24 PM
Extract phone number front block of text Tech Excel Discussion (Misc queries) 6 August 8th 05 04:07 PM
select block of rows w/data between blank rows Janna Excel Programming 6 February 13th 05 02:45 AM
I Need to divide all cells in rows 2 and 3 by 100 Brent E Excel Discussion (Misc queries) 3 December 23rd 04 11:27 PM


All times are GMT +1. The time now is 05:22 PM.

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

About Us

"It's about Microsoft Excel"