I'm a newbie at VBA and I created a userform to Vlookup information on excel sheet and place it back on userform textboxes.
Vlookup value is based on plane models, so once the user selects the model within a combobox and hits the command button it simply runs the vlookups.
Then the user needs to check if any of the returning information on the textboxes is wrong or missing, so he just replace textbox data by typing in new/missing info about that plane model, and the best way to do this I could think of were using find function to select model matching row and then Offset information from column to column.
The problem happens with two textboxes that should return Dates in Date format and send it back also as a date. Instead it returns data in text format and send it back same way.
My code is below I don't know if there is a smarter solution, please if any of the experts can help me to cast a light on this problem I would be very thankful:
'Change data according to model found
Dim FindString As String
Dim Rng As Range
Dim b As Integer
'Find model and input date
FindString = ModelCombo.Value
If Trim(FindString) <> "" Then
With Sheets("Database").Range("B:B")
Set Rng = .find(what:=FindString, _
after:=.Cells(.Cells.Count), _
LookIn:=xlValues, _
lookat:=xlWhole, _
searchorder:=xlByRows, _
searchdirection:=xlNext, _
MatchCase:=False)
If Not Rng Is Nothing Then
Application.Goto Rng, True
Else
MsgBox "Nothing found"
End If
End With
End If
MsgBox "Date has been saved successfully!"
'Offset to replace values starting on column B
ActiveCell.Offset(0, 1).Select
ActiveCell.Value = textbox1
ActiveCell.Offset(0, 1).Select
ActiveCell.Value = modeltexttbox
ActiveCell.Offset(0, 1).Select
ActiveCell.Value = ComboBox1
ActiveCell.Offset(0, 1).Select
ActiveCell.Value = textbox3
ActiveCell.Offset(0, 2).Select
ActiveCell.Value = ComboBox2
ActiveCell.Offset(0, 1).Select
ActiveCell.Value = textboxsellvalue
ActiveCell.Offset(0, 1).Select
ActiveCell.Value = textbox_amount
ActiveCell.Offset(0, 1).Select
ActiveCell.Value = ComboBox3
ActiveCell.Offset(0, 1).Select
ActiveCell.Value = prodstart
ActiveCell.Offset(0, 2).Select
ActiveCell.Value = releasedate
ActiveCell.Offset(0, 2).Select
ActiveCell.Value = airplane_textbox
question from:
https://stackoverflow.com/questions/65901923/copy-date-from-textbox-and-replace-on-excel-cell 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…