CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Oct 2010
    Posts
    17

    Unhappy help me in the code !!

    Code:
    Option Explicit
    Dim xl As New Excel.Application
    Dim xlsheet As Excel.Worksheet
    Dim xlsheet1 As Excel.Worksheet
    Dim xlwbook As Excel.Workbook
    
    Private Sub Command1_Click()
    Dim fI As Integer
    Dim fI1 As Integer
    Dim cl As String
    Dim cl1 As String
    Dim r As Integer
    
    Set xlwbook = xl.Workbooks.Open(App.Path & "\1.xls")
    Set xlsheet = xlwbook.Sheets.Item(1)
    Set xlsheet1 = xlwbook.Sheets.Item(2)
     For fI1 = 1 To 31
                If xlsheet1.Cells(fI1, 1) = "" Then
             xl.ActiveWorkbook.Close False, CStr(App.Path & "\12.xls")
                Else
                    cl = xlsheet1.Cells(fI1, 1)
                    cl1 = 0
                    For fI = 1 To 31
                        If xlsheet.Cells(fI, 1) = cl Then
                            cl1 = cl1 & fI & ","
                            Text1(0).Text = cl1
                        Else
                             Resume Next
                        End If
                End If
            Next fI1
    
    
     xl.ActiveWorkbook.Close False, CStr(App.Path & "\12.xls")
    
    
    Exit Sub
    
    
    fErrHandler:
    MsgBox "Error occurred while reading Excel File. Please note that File must be placed in same directory as the program and its name should be Numbers.xls." & vbCrLf & "Error: " & Err.Description, , "Error Reading File"
    Exit Sub
    End Sub
    the code is work but when i need it to continue search in rows it stop (read command ))

    how i can make it resume the NEXT for FI in ELSE ????

    regards

  2. #2
    Join Date
    Oct 2010
    Posts
    17

    Re: help me in the code !!

    what i need is that

    Code:
     For fI1 = 1 To 31
                If xlsheet1.Cells(fI1, 1) = "" Then
             xl.ActiveWorkbook.Close False, CStr(App.Path & "\12.xls")
                Else
                    cl = xlsheet1.Cells(fI1, 1)
                    cl1 = 0
                    For fI = 1 To 31
                        If xlsheet.Cells(fI, 1) = cl Then
                            cl1 = cl1 & fI & ","
                            Text1(0).Text = cl1
                        Else
                             Resume Next (her I need to resume FI FOR loop again to continue FI until 31  )
                        End If
                End If
            Next fI1 (her I need to Resume FI1 LOOP again until when there are no Text  )
    Last edited by mot1639; October 4th, 2010 at 10:18 AM.

  3. #3
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: help me in the code !!

    You use Next with the For command.
    Resume Next is for error trapping not looping.

    In you case above the Next would need to go after the end if not within the else statement.
    If you want it not to loop when the if condition is true then inside the If you would place and Exit For statement to have it break out of the loop.
    Always use [code][/code] tags when posting code.

  4. #4
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: help me in the code !!

    This might help:


    Code:
    Sub FindLastRow()
    
    Dim LastRow As Long
    
    	If WorksheetFunction.CountA(Cells) > 0 Then
    
    		'Search for any entry, by searching backwards by Rows.
    
    		LastRow = Cells.Find(What:="*", After:=[A1], _
    
    			  SearchOrder:=xlByRows, _
    
    			  SearchDirection:=xlPrevious).Row
    
    			  MsgBox LastRow
    
    	End If
    
    End Sub
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured