Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
|
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 4th, 2005, 07:15 AM
Friend of Wrox
 
Join Date: Jan 2005
Posts: 1,525
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to crmpicco Send a message via AIM to crmpicco Send a message via MSN to crmpicco Send a message via Yahoo to crmpicco
Default last occurance omitted - LOOP error?

The code below is my looping structure for the creation of the XML variables that go into making the XML file.

The problem i am experiancing is that the current structure does not pick up the LAST occurance in the loop. It just seems to ignore it. Can anyone notice the problem?

Code:
For iRow = 1 To iTotalRows    ' for {2}

            flag = False

            For iCol = 1 To (iTotalCols)    ' for {3}

                bFoundCellCol = False

                sRange = getColumnLetter(iCol) & iRow
                Range(sRange).Select

                iCurrentCellCol = Range(sRange).Interior.ColorIndex

                'MsgBox "range(srange) = " & Range(sRange)

                For j = LBound(gaRulesColour) To UBound(gaRulesColour)    ' for {4}
                    iPos = InStr(gaRulesColour(j), "/")
                    iArrayColour = Mid(gaRulesColour(j), iPos + 1, Len(gaRulesColour(j)) - 1)


                    'If the_Heading <> "" Then
                    'MsgBox the_Heading
                    'End If

                    If iCurrentCellCol = iArrayColour Then    ' if {1}


                        If the_Heading <> "" Then

                            rulesXML = rulesXML & "<fare_rule_lines>"
                            rulesXML = rulesXML & "<heading>" & fix_characters(Trim(the_Heading)) & "</heading>"
                            rulesXML = rulesXML & "<content>" & fix_characters(Trim(the_Content)) & "</content>"
                            rulesXML = rulesXML & "</fare_rule_lines>"

                        End If

                        the_Heading = fix_ampersand(Trim(Range(sRange).Text))
                        the_Content = "&lt;table&gt;"

                    End If

                    iPos = InStr(gaContentColour(j), "/")
                    iArrayContentColour = Mid(gaContentColour(j), iPos + 1, Len(gaContentColour(j)) - 1)

                    'sRange = getColumnLetter(iCol + 1) & iRow
                    iCurrentCellColour = Range(sRange).Interior.ColorIndex
                    If iCurrentCellColour <> 2 Then    ' if {1}

                        'sRange = getColumnLetter(iCol + 1) & iRow
                        'sRightRange = sRange

                        ' if the current cell is the same as the colour of the content in the template
                        If iCurrentCellColour = iArrayContentColour Then
                            iFlag = 0

                            'the_Content = the_Content & "&lt;tr&gt;"
                            'the_Content = the_Content & "&lt;td&gt;"
                            'the_Content = the_Content & Trim(Range(sRange).Text)
                            'the_Content = the_Content & "&lt;/td&gt;"
                            While flag <> True

                                If iRow = 88 Then
                                    iRow = 88
                                End If
                                sRightRange = getColumnLetter(iCol + iFlag + 1) & iRow

                                'sRange = getColumnLetter(iCol + iFlag) & iRow

                                ' if it is not empty then write another <td>
                                If iFlag = 0 And Trim(Range(sRightRange).Text) <> "" Then
                                    the_Content = the_Content & "&lt;tr&gt;"
                                    the_Content = the_Content & "&lt;td&gt;"
                                    the_Content = the_Content & fix_ampersand_to_amp(Trim(Range(getColumnLetter(iCol + iFlag) & iRow).Text))
                                    the_Content = the_Content & "&lt;/td&gt;"
                                ElseIf iFlag = 0 And Trim(Range(sRightRange).Text) = "" Then
                                    the_Content = the_Content & "&lt;tr&gt;"
                                    the_Content = the_Content & "&lt;td&gt;"
                                    the_Content = the_Content & fix_ampersand_to_amp(Trim(Range(getColumnLetter(iCol + iFlag) & iRow).Text))
                                    the_Content = the_Content & "&lt;/td&gt;"
                                    the_Content = the_Content & "&lt;/tr&gt;"
                                    flag = True
                                ElseIf iFlag <> 0 And Trim(Range(sRightRange).Text) = "" Then
                                    the_Content = the_Content & "&lt;td&gt;"
                                    the_Content = the_Content & fix_ampersand_to_amp(Trim(Range(getColumnLetter(iCol + iFlag) & iRow).Text))
                                    the_Content = the_Content & "&lt;/td&gt;"
                                    the_Content = the_Content & "&lt;/tr&gt;"
                                    flag = True
                                ElseIf iFlag <> 0 And Trim(Range(sRightRange).Text) <> "" Then
                                    the_Content = the_Content & "&lt;td&gt;"
                                    the_Content = the_Content & fix_ampersand_to_amp(Trim(Range(getColumnLetter(iCol + iFlag) & iRow).Text))
                                    the_Content = the_Content & "&lt;/td&gt;"

                                End If    ' if the cell is empty

                                'MsgBox the_Content
                                iFlag = iFlag + 1

                            Wend    ' while flag <> true

                        End If    ' if the cell is the same as the colour in the template

                    End If

                Next j

                ' loop through each column
            Next iCol

            ' loop through each row
        Next iRow
www.crmpicco.co.uk
www.crmpicco.co.uk.tt
www.milklemonadechocolate.uk.tt
www.griswolds.uk.tt
www.piccosmini.co.uk.tt
www.morton.uk.tt
__________________
_______________________
Ayrshire Minis - a Mini E-Community
http://www.ayrshireminis.com
http://www.crmpicco.co.uk
 
Old May 4th, 2005, 11:06 AM
Friend of Wrox
 
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

Does it skip the last iRow, iCol or both?


What do all those URLs refer to?
 
Old May 5th, 2005, 05:19 AM
Friend of Wrox
 
Join Date: Jan 2005
Posts: 1,525
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to crmpicco Send a message via AIM to crmpicco Send a message via MSN to crmpicco Send a message via Yahoo to crmpicco
Default

Does it skip the last iRow, iCol or both?
--

howdo you mean?

www.crmpicco.co.uk
www.crmpicco.co.uk.tt
www.milklemonadechocolate.uk.tt
www.griswolds.uk.tt
www.piccosmini.co.uk.tt
www.morton.uk.tt
 
Old May 5th, 2005, 01:45 PM
Friend of Wrox
 
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

You have a loop with another loop nested within it. Which is it that skips the last element?

You have 6 URLs as your signature,      To what do they point?
I am leery of following links that I know nothing about . . .
I presume you want people to follow these links; how about a brief description of what it is that they are?





Similar Threads
Thread Thread Starter Forum Replies Last Post
Occurance Index d_sathish XSLT 2 November 4th, 2005 04:45 AM
loop error crmpicco Classic ASP Databases 7 March 4th, 2005 10:59 AM
11th occurance ONLY crmpicco Classic ASP Basics 1 February 11th, 2005 04:01 AM
pick out the 11th occurance crmpicco Classic ASP Basics 4 February 11th, 2005 04:00 AM
xslt distinct and countnumber of occurance imran_py XSLT 1 May 5th, 2004 02:50 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.