|
-
October 4th, 2010, 08:46 AM
#1
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
-
October 4th, 2010, 08:54 AM
#2
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.
-
October 4th, 2010, 11:21 AM
#3
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.
-
October 4th, 2010, 12:02 PM
#4
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|