0
Reply

Excel vba to vb.net

David Eastwood

David Eastwood

Aug 23 2009 7:04 AM
3.3k
Hi All I am beginner at vb.net can someone help me with this code
I have a warning.   Variable 'cell' is used before it has been assigned a value. A null reference exception could result at runtime.

[code]
Private Sub btnFind_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFind.Click
        Dim Forms As New Form1
        Forms.ListBox1.ClearSelected()
        Globals.ThisWorkbook.Sheets.Equals("A2:H5000").ToString()

        Dim ThisWorkBook As String
        Dim Combotext As String
        Dim ListText As String
        Dim startDate As Date
        Dim endDate As Date
        Dim name As String
        Dim site As String
        Dim range As Excel.Range
        Dim cell As Excel.Range

        startDate = cmbStartDate.ValueMember
        endDate = cmbEndDate.ValueMember
        name = cmbEmployee.ValueMember
        site = cmbSiteReference.ValueMember

        If cmbStartDate.ValueMember = "" Or cmbEndDate.ValueMember = "" Or cmbEmployee.ValueMember = "" Or cmbSiteReference.ValueMember = "" Then
            MsgBox("Make sure you select all values from drop downs", vbCritical, "Missing Values Error")
            Exit Sub
        End If

        'Dim extra_hours As Long
        ' To account for total hours worked by the person in given time
        Dim total_hours As Long
        total_hours = 0
        'extra_hours = 0
        Dim i As Long
        Dim Count, count2 As Long
        Count = 0
        count2 = 2
        ' sheet2.Cells(1, 2).Value = "test"
        'Application.ScreenUpdating = False
        'Sheet1.Activate

        'Application.ScreenUpdating = False
        'MsgBox ActiveSheet.name
        Dim checkBox1 As New CheckBox
        For i = 2 To 65536

             AddHandler(cell.Value) ........? what do i put here to make this work

            If checkBox1.Checked = True Then
                If cell(i, 1).Value >= startDate And cell(i, 1).Value <= endDate And cell(i, 2).Value = name And cell(i, 3).Value = site Then
[\code]