PDA

View Full Version : Solved: Populate boxes on form with value from 1 cell



feathers212
04-12-2007, 11:24 AM
I have a form, AddLineItem, with multiple text and combo boxes. When the Log_Waste button is clicked, the information from these boxes get entered into their appropriate cells on the sheet. There are two boxes on my form (Line_Item is a combobox and Item_Comment is a textbox) that get entered into a single spreadsheet cell with ": " between them.

Range("H" & RowNum).Value = Line_Item.Value & ": " & Item_Comment.Value


Later, a user can double-click on the row to edit it. I want the information from that row to be populated back into the form. My problem is I'm not sure how to split apart the information in the column H cell into it's two components on the AddLineItem form.

Any thoughts?

Paul_Hossler
04-12-2007, 07:06 PM
If I understand what you wanted, the quick way would be to use Split ()or InStr() after you get the value back

HTH, Paul


Sub Test()
Dim Line_Item As String, Item_Comment As String
Dim vSplit As Variant
'setup using Dimmed variables, instead of Form for demo
Line_Item = "ABCD"
Item_Comment = "EFGH"
'put in worksheet
ActiveSheet.Range("H2").Value = Line_Item & ": " & Item_Comment

'bring it back and split
vSplit = Split(ActiveSheet.Range("H2").Value, ":")
MsgBox vSplit(0)
MsgBox vSplit(1)
End Sub


Sub Test1()
Dim Line_Item As String, Item_Comment As String
Dim n As Long
Dim s As String
'setup using Dim variables, instead of Form
Line_Item = "ABCD"
Item_Comment = "EFGH"
'put in worksheet
ActiveSheet.Range("H2").Value = Line_Item & ": " & Item_Comment

'bring it back and split
s = ActiveSheet.Range("H2").Value
n = InStr(s, ":")
MsgBox Left(s, n - 1)
MsgBox Right(s, Len(s) - n)
End Sub

feathers212
04-12-2007, 07:18 PM
Thanks Paul! The Split() was exactly what I was looking to use. Works perfectly!