• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

error in range using combobox

noobexcel

New Member
this is the code


Private Sub closeButton_Click()

Unload Me

End Sub


Private Sub cmdButton_Click()

Dim lRow As Long

Dim lAct As Long

Dim ws As Worksheet

Set ws = Worksheets("RfiDatas")


'find first empty row in database

lRow = ws.Cells(Rows.Count, 1) _

.End(xlUp).Offset(1, 0).Row


lAct = Me.cboActivity.ListIndex


'check for a RFI number

If Trim(Me.cboActivity.Value) = "" Then

Me.cboActivity.SetFocus

MsgBox "Please enter a RFI number"

Exit Sub

End If


'copy the data to the database

With ws

.Cells(lRow, 1).Value = Me.cboActivity.Value

.Cells(lRow, 2).Value = Me.cboStructure.Value

.Cells(lRow, 3).Value = Me.txtGl.Value

.Cells(lRow, 4).Value = Me.cboLocation.Value

.Cells(lRow, 5).Value = Me.txtRfinumber.Value

.Cells(lRow, 6).Value = Me.txtDate.Value

.Cells(lRow, 7).Value = Me.cboInspector.Value

End With


'clear the data

Me.cboActivity.Value = ""

Me.cboStructure.Value = ""

Me.txtGl.Value = ""

Me.cboLocation.Value = ""

Me.txtRfinumber.Value = ""

Me.txtDate.Value = Format(Date, "Medium Date")

Me.cboInspector.Value = ""

Me.cboActivity.SetFocus


End Sub


Private Sub UserForm_Initialize()

Dim cAct As Range

Dim cStruc As Range

Dim cLoc As Range

Dim cInsp As Range

Dim ws As Worksheet

Set ws = Worksheets("LookupDatas")


For Each cAct In ws.Range("ActList")

With Me.cboActivity

.AddItem cAct.Value

.List(.ListCount - 1, 1) = cAct.Offset(0, 1).Value

End With

Next cAct


For Each cStruc In ws.Range("StrucList")

With Me.cboStructure

.AddItem cStruc.Value

End With

Next cStruc


For Each cLoc In ws.Range("LocList")

With Me.cboLocation

.AddItem cLoc.Value

End With

Next cLoc


For Each cInsp In ws.Range("InspList")

With Me.cboInspector

.AddItem cInsp.Value

End With

Next cInsp


Me.txtGl.Value = ""

Me.txtRfinumber.Value = ""

Me.txtDate.Value = Format(Date, "Medium Date")

Me.cboActivity.SetFocus


End Sub


Can you help me guys im new in excel VB.. Tnx in advance
 
Back
Top