VB: Private Sub UserForm_Initialize() [INDENT]tb1.Text = Format(Worksheets("Input").Cells(1, 1), "$#,##0")[/INDENT][INDENT]tb2.Text = Format(Worksheets("Input").Cells(2, 1), "0%")[/INDENT]End Sub If you like these VB formatting tags please consider sponsoring the author in support of injured Royal MarinesThe code works, but since the textbox are being populated with numbers I'm assuming the code needs to be changed to remove the "text" part. I tried entering "number" instead of text but got an error message. (Note- "N/A" is a possible option for the values)
VB: Private Sub tbstockpurchprice_Exit(ByVal Cancel As MSForms.ReturnBoolean) tbstockpurchprice = Format(tbstockpurchprice, "$#,##0.00") End Sub Private Sub tbstockpurchprice_Change() OnlyNumbers End Sub Private Sub OnlyNumbers() If TypeName(Me.ActiveControl) = "TextBox" Then With Me.ActiveControl If Not IsNumeric(.Value) And .Value vbNullString Then MsgBox "Sorry, only numbers allowed" .Value = vbNullString End If End With End If End Sub If you like these VB formatting tags please consider sponsoring the author in support of injured Royal MarinesThen the information is transferred to my spreadsheet with the following code in the Private Sub CommandButton1_Click routine:
VB: .Cells(6, 15).Value = Val(Me.tbstockpurchprice) If you like these VB formatting tags please consider sponsoring the author in support of injured Royal MarinesThis does not seem to work when I format the numbers as above. The data does not transfer to the cell specified or anywhere else for that matter. If the numbers entered into the userform are not formatted as above they transfer just fine into the spreadsheet as numeric values and can be used in calculations within the spreadsheet. There seems to be a conflict between the text formatting and the Val() function. If I don't use the Val() function the text is transferred into the spreadsheet but then cannot be used in calculations.
VB: 'Validate Job Number Workbooks("Template Generator.xls").Forms("ProjectInfo").Activate If TextBox("InptJobNum").Text = "" Then MsgBox "Please Insert Job Number" TextBox("InptJobNum").Select Exit Sub Else Jnum = TextBox("InptJobNum") 'Specify Job Number Workbooks("Job Log.xls").Sheets("Job Log").Activate End If If WorksheetFunction.CountIf(Range("A2:A1000"), Jnum) = 0 Then Workbooks("Template Generator.xls").Forms("ProjectInfo").Activate MsgBox "Invalid Job Number, or cannot be located... Please correct and try again" TextBox("InptJobNum").Select Exit Sub End If If you like these VB formatting tags please consider sponsoring the author in support of injured Royal Marines
Private Sub textbox1_Change() textbox1 = Format(valor, "#,###") End SubThat works to formatting the number, but I am not able to insert the decimal part
Private Sub textbox1_Change() textbox1 = Format(valor, "#,##0.00") End SubAfter I insert the first digit it formats the number, but do not allow me to keep inserting the other digits.
TextBox2 = ActiveCell.Offset(0, 23).ValueWhat I was wondering is if it is possible for the textbox to show the value with
Private Sub TextBox22_Initialize() TextBox22.Value = Format(TextBox22.Value, Evaluate(TextBox22.ControlSource).NumberFormat) End SubThanks Conor
VB: Private Sub UserForm_Initialize() 'Add list entries to the combo boxes. The value of each 'box matches the existing SR Information spreadsheet entries With Sheets("SR Information") .Range("A2", .Cells(Rows.Count, "A").End(xlUp)).Name = "MyRange" End With SRnumber.RowSource = "MyRange" ' Set initial values to TextBoxes -not needed, just for testing- ' NBdate.Text = "Test NBD SR Number" ' ApartNumber.Text = "Test AP SR Number" ' UPdetails.Text = "Test UD SR Number" End Sub Private Sub SRnumber_Change() Dim ServiceRequestNumber As String Dim c As Range Dim rngG As Range Sheets("SR Information").Select With Selection 'Find value in ComboBox, and select row ServiceRequestNumber = SRnumber.Value For Each c In Intersect(ActiveSheet.UsedRange, Columns("a")) If c = ServiceRequestNumber Then If rngG Is Nothing Then Set rngG = c.EntireRow Set rngG = Union(rngG, c.EntireRow) End If Next c rngG.Select ' [B][COLOR="Red"] ' >Insert Code Here?< Update other TextBoxes with information contained in specific cells on the selected row[/COLOR][/B] ' End With End Sub If you like these VB formatting tags please consider sponsoring the author in support of injured Royal Marines