understanding code

novice1

Board Regular
Joined
Dec 11, 2007
Messages
146
What does this part of the code do?

Code:
If LenB(Table) = 0 Or Table < 11 Then

Its part of this code is below

Code:
If LenB(Table) = 0 Or Table < 11 Then 
    With Application.WorksheetFunction 
        Table = .CountA(Range("Expense").Columns(1)) + 1 
    End With 
End If
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
The LenB function returns the number of characters in a variable. So the code is testing that Table is not blank (zero length) or is less than 11.
 
Upvote 0
After I enter the 12th entry in a my table of 500 available rows, it deletes the 11th entry. I had change the Table < 11 to 500 (table has 500 rows), then it doesn't delete the 11th entry. Any reason for the logic?

the entire code

Code:
Dim I As Integer
Dim tCol As Integer
Dim ExRange As Range
Dim Ans
Dim ToRow As Integer
Dim temp_row As Integer

Ans = MsgBox("Did your employer reimburse you for this expense?", vbQuestion + vbYesNo, "PerDiem Traveler")
If Ans = vbNo Then
    On Error Resume Next
    If Me.cboDesc.Text = vbNullString Or Me.Amnt.Text = vbNullString Then
        MsgBox "All entries must be completed before your expense can be registered.", vbExclamation, "PerDiem Traveler"
        Exit Sub
    End If
    On Error Resume Next
    If Me.cboDesc.Text = vbNullString Or Me.Amnt.Text = vbNullString Then
        MsgBox "All entries must be completed before your expense can be registered.", vbExclamation, "PerDiem Traveler"
        Exit Sub
    End If
    If cboCat = "All Categories" Then
        MsgBox "Select an expense category", vbExclamation, "PerDiem Traveler"
    Else
        If LenB(Table) = 0 Or Table < 1000 Then
            With Application.WorksheetFunction
                    Table = .CountA(Range("Expense").Columns(1)) + 1
            End With
        End If
        AddNew
        With Me.ListBox3
            If .ListIndex > -1 Then
                ToRow = Sheets("Calculator").Range("BB11").Offset(.ListIndex, 0).Value
                On Error GoTo 0
                If LenB(.Value) > 0 And Ent5.Caption = "Update" Then 'updating a item....
                    temp_row = .ListIndex
                    Range("Expense").Cells(ToRow, 2) = CDate(Me.Date5)
                    Range("Expense").Cells(ToRow, 3) = cboCat.Value
                    Range("Expense").Cells(ToRow, 4) = cboDesc.Value
                    Range("Expense").Cells(ToRow, 5) = CCur(Replace(Me.Amnt, "$", ""))
                    Range("Expense").Cells(ToRow, 6) = "$0.00"
                    Load_Itemized
                    Exit Sub
                         End If
            Else
                Range("Expense").Cells(Table, 1) = Application.Max(Range("AU11:AU500")) + 1
                Range("Expense").Cells(Table, 2) = CDate(Date5)
                Range("Expense").Cells(Table, 3) = cboCat.Value
                Range("Expense").Cells(Table, 4) = cboDesc.Value
                Range("Expense").Cells(Table, 5) = CCur(Replace(Amnt, "$", ""))
                Range("Expense").Cells(Table, 6) = "$0.00"
            End If
        End With
        Range("AV11:AZ500").Sort key1:=Range("AV11"), order1:=xlAscending, Header:=xlNo
        LoadList
        NewExpense
    End If
    For tCol = 42 To 46
       Set ExRange = ActiveSheet.Range(Cells(10, tCol), Cells(30, tCol))
       ExRange.Sort key1:=ExRange.Cells(1, 1), order1:=xlAscending, Header:=xlYes
    Next tCol
Else
    frmComp.Show
End If
 
Upvote 0
Where are you declaring Table, and where are you assigning it a value other than in the line within your If clause? I don't see any deletion taking place in the code you posted.
 
Upvote 0
I declare the Table as Private Table As Long. As for assigning it a value, thats the only place I have it
 
Upvote 0

Forum statistics

Threads
1,224,522
Messages
6,179,292
Members
452,902
Latest member
Knuddeluff

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top