View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Iain King Iain King is offline
external usenet poster
 
Posts: 32
Default table of contents

How can i make table of contents for 15000 row, for example
year 2001
row 1

year 2002
row 5000

year 2003
row 10000



I'm going to assume that your main sheet looks something like this:

A B C
2001 Data Here
2001 Data Here
2001 Data Here
2002 Data Here
2002 Data Here
2003 Data Here
2003 Data Here
2003 Data Here

With your main sheet called "MAIN", and contents sheet called "CONTENTS"

dim entryRow as long
dim dataRow as long
dim lastYear as long
dim thisYear as long
dim lastRow as long

entryRow = 1
lastYear = 0

lastRow = Sheets("MAIN").Range("A:A").Count

for dataRow = 1 to lastRow
thisYear = Sheets("MAIN").Cells( dataRow, 1).Value
if thisYear<lastYear then
Sheets("CONTENTS").Cells( entryRow, 1).Value = "Year " + Format(
thisYear)
Sheets("CONTENTS").Cells( entryRow + 1, 1).Value = dataRow
lastYear = thisYear
entryRow = entryRow + 3
endif
next


Iain King