Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 74
Default Nested loops??



Good Day Group,

Struggle with below problem, grateful for some hints how start thinking.

Brgds

CG Rosén

My database looks like this:

A B C D E
Item Type SubType Size Stock
xxx Spirits Aquavit 0,75 2
zzzz Spirits Aquavit 0,50 4
yyy Spirits Brandy 1,00 1
qqq Spirits Brandy 0,70 5
www Spirits Cognac 0,5 3
etc etc

Trying to present the data in a worksheet like this:

A B C D E
1 1,00 0,75 0,70 0,50
2 Aquavit 0 2 0 4
3 Brandy 1 0 1 0
4 Cognac 0 0 0 3
etc
etc

This is start to do it by a nested loop (gives run time error 91)

SubType = Array("Aquavit", _
"Brandy", _
"Cognac", _
"Gin", _
"Liqueuer", _
"Other Spirits", _
"Rum", _
"Whisky", _
"Vodka")

For i = 0 To 8

With Worksheets(1).Range("C1:C10000")

Set k = .Find(SubType(i), _
LookIn:=xlValues, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows)

If Not k Is Nothing Then
firstAddress = k.Address
Do
'---------------------------------------------------------------------
With Worksheets(1).Range("D1:D10000")

Set j = .Find("1,00", _
LookIn:=xlValues, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows)

If Not j Is Nothing Then
secAddress = j.Address
Do
r = k.Row

Code ??????

Set j = .FindNext(j)
Loop While Not j Is Nothing And j.Address < secAddress

End If

End With
'---------------------------------------------------------------------------
--
Set k = .FindNext(k)
Loop While Not k Is Nothing And k.Address < firstAddress
??????????????????????????? error 91

End If
End With
Next i


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Nested loops??

You can do this with a pivot table without any code.

--
Regards,
Tom Ogilvy

"CG Rosén" wrote in message
...


Good Day Group,

Struggle with below problem, grateful for some hints how start thinking.

Brgds

CG Rosén

My database looks like this:

A B C D E
Item Type SubType Size Stock
xxx Spirits Aquavit 0,75 2
zzzz Spirits Aquavit 0,50 4
yyy Spirits Brandy 1,00 1
qqq Spirits Brandy 0,70 5
www Spirits Cognac 0,5 3
etc etc

Trying to present the data in a worksheet like this:

A B C D E
1 1,00 0,75 0,70 0,50
2 Aquavit 0 2 0 4
3 Brandy 1 0 1 0
4 Cognac 0 0 0 3
etc
etc

This is start to do it by a nested loop (gives run time error 91)

SubType = Array("Aquavit", _
"Brandy", _
"Cognac", _
"Gin", _
"Liqueuer", _
"Other Spirits", _
"Rum", _
"Whisky", _
"Vodka")

For i = 0 To 8

With Worksheets(1).Range("C1:C10000")

Set k = .Find(SubType(i), _
LookIn:=xlValues, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows)

If Not k Is Nothing Then
firstAddress = k.Address
Do
'---------------------------------------------------------------------
With Worksheets(1).Range("D1:D10000")

Set j = .Find("1,00", _
LookIn:=xlValues, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows)

If Not j Is Nothing Then
secAddress = j.Address
Do
r = k.Row

Code ??????

Set j = .FindNext(j)
Loop While Not j Is Nothing And j.Address < secAddress

End If

End With

'---------------------------------------------------------------------------
--
Set k = .FindNext(k)
Loop While Not k Is Nothing And k.Address < firstAddress
??????????????????????????? error 91

End If
End With
Next i




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
Help with nested for loops [email protected] Excel Discussion (Misc queries) 5 May 2nd 07 05:30 PM
Help with nested for loops [email protected] Excel Worksheet Functions 5 May 2nd 07 05:30 PM
Max limit of 7 nested loops Subu Excel Worksheet Functions 2 May 28th 05 02:14 PM
RANGE & NESTED LOOPS jay dean Excel Programming 1 January 29th 04 11:43 PM
LOOPS Fernando Duran Excel Programming 2 September 3rd 03 01:07 AM


All times are GMT +1. The time now is 03:49 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"