Inputbox string compare with cell value - problem??

didijaba

Well-known Member
Joined
Nov 26, 2006
Messages
511
HI, first thanks for any help you can give me. I have userform with one textbox (Reg2). When I fill it with number it does not recognise numbers in cells that are same as string in inputbox?? How can I solve this?
Code:
Private Sub Reg2_Change()
Dim i As Long

If Sheet3.Cells(1, 11) = "FORM_3" Then

With Sheet6 
lastrow = .Cells(.Rows.Count, "A").End(xlUp).Row
End With

For i = 1 To lastrow
    If UserForm1.Reg2.Text <> Sheet6.Cells(i, 1).Value Then
        Exit Sub
    Else
    Exit For
    End If
Next i

Dim InvNumber As String
InvNumber = UserForm1.Reg2.Text

With Sheet7
lastrow3 = .Cells(.Rows.Count, "A").End(xlUp).Row
End With

For i = 1 To lastrow3

Select Case Val(UserForm1.txtMemNo.Text)

    Case Sheet7.Cells(i, 1).Value
                    Select Case Sheet7.Cells(1, 6).Value
                       Case Sheet7.Cells(i, 2).Value
                            Select Case Sheet7.Cells(i, 3)
                                Case vbNull
                                    Sheet7.Cells(i, 3) = CDate(Format(Now(), "dd/mm/yy hh:mm:ss"))
                                    MsgBox "ITEM IS GIVEN!"
                                    Exit For
                                 Case Is <> vbNull
                                
                                    Select Case Sheet7.Cells(i, 4).Value
                                        Case vbNull
                                            Sheet7.Cells(i, 4) = CDate(Format(Now(), "dd/mm/yy hh:mm:ss"))
                                            MsgBox "ITEM IS RETURNED"
                                            Exit For
                                    Case Is <> vbNull
                                     End Select
                            End Select
                    
                        Case Is <> Sheet7.Cells(i, 2)
                                With Sheet7
                                    .Cells(lastrow3 + 1, 1) = Val(UserForm1.txtMemNo.Text)
                                    .Cells(lastrow3 + 1, 2) = Val(InvNumber)
                                    .Cells(lastrow3 + 1, 3) = CDate(Format(Now(), "dd/mm/yy hh:mm:ss"))
                                End With
                                MsgBox "ITEM IS GIVEN"
                                Exit For
                        End Select
  
Case Is <> Sheet7.Cells(i, 1).Value
                    With Sheet7
                        .Cells(lastrow3 + 1, 1) = Val(UserForm1.txtMemNo.Text)
                        .Cells(lastrow3 + 1, 2) = Val(InvNumber)
                        .Cells(lastrow3 + 1, 3) = CDate(Format(Now(), "dd/mm/yy hh:mm:ss"))
                    End With
                    MsgBox "ITEM IS GIVEN"
                    Exit For

End Select
Next i
End If
End Sub
 
Last edited:

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
I don't see where the InputBox is invoked, but you could either apply Val to the result of the input box to convert it to a number, or you could test the input box value against CStr(cellValue) to convert the cell value to text.
 
Upvote 0
thanks for your help, your advice was 100% correct, thanks. I simply rewrote if-then procedure, and it worked fine.
 
Upvote 0

Forum statistics

Threads
1,203,522
Messages
6,055,893
Members
444,832
Latest member
Kauri

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