Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I am collecting data from users in a Excel spreadsheet. To ensure all
the required fields are filled out, I have created a userform that loads on opening of the spread sheet. Currently there are three Textboxes a command button writes the data to the sheet and highlights in pink any not filledout. I need a higher level of data vaildation on the two other text boxes. Textbox2 must contain an email address (checking for hyperlinked content is probably the easiest way to vaildate for this) Textbox3 must contain only a 9 digit numerical number Option Explicit Dim y As Long Const pink = 16761855 Private Sub CommandButton1_Click() Dim EmptyBoxes As Integer EmptyBoxes = EmptyBoxes + check(TextBox1) EmptyBoxes = EmptyBoxes + check(TextBox2) EmptyBoxes = EmptyBoxes + check(TextBox3) If EmptyBoxes = 0 Then ActiveWorkbook.Save Unload Me End If End Sub Function check(tb As Control) Dim res As Integer res = 0 If tb.Text = vbNullString Then res = 1 tb.BackColor = pink Else Cells(y, CLng(Right(tb.Name, 1))) = tb End If check = res End Function Private Sub UserForm_Activate() y = [A1].End(xlDown).Row + 1 End Sub |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Option Explicit
Dim y As Long Const pink = 16761855 Private Sub CommandButton1_Click() Dim EmptyBoxes As Integer IF check1 AND check2 AND check3 Then ActiveWorkbook.Save Unload Me else msgbox "Check text boxes" End If End Sub Function check1 as Boolean Dim res As Integer res = 0 If textbox1.Text = vbNullString Then textbox1.BackColor = pink Else Cells(y, CLng(Right(textbox1.Name, 1))) = textbox1 check1 = True End If End Function Private Sub UserForm_Activate() y = [A1].End(xlDown).Row + 1 End Sub function check2 as boolean 'check textbox2 has a 9 digit number if isnumber(textbox2.text) then if len(textbox2.text)=9 then check2 = True end if end if if not check2 then textbox2.BackColor = pink end if end function function check3 as boolean 'check textbox3 is an address ??? If textbox3.Text = vbNullString Then textbox3.BackColor = pink Else check3 = True End If end function "macro rewind" wrote in message ... I am collecting data from users in a Excel spreadsheet. To ensure all the required fields are filled out, I have created a userform that loads on opening of the spread sheet. Currently there are three Textboxes a command button writes the data to the sheet and highlights in pink any not filledout. I need a higher level of data vaildation on the two other text boxes. Textbox2 must contain an email address (checking for hyperlinked content is probably the easiest way to vaildate for this) Textbox3 must contain only a 9 digit numerical number Option Explicit Dim y As Long Const pink = 16761855 Private Sub CommandButton1_Click() Dim EmptyBoxes As Integer EmptyBoxes = EmptyBoxes + check(TextBox1) EmptyBoxes = EmptyBoxes + check(TextBox2) EmptyBoxes = EmptyBoxes + check(TextBox3) If EmptyBoxes = 0 Then ActiveWorkbook.Save Unload Me End If End Sub Function check(tb As Control) Dim res As Integer res = 0 If tb.Text = vbNullString Then res = 1 tb.BackColor = pink Else Cells(y, CLng(Right(tb.Name, 1))) = tb End If check = res End Function Private Sub UserForm_Activate() y = [A1].End(xlDown).Row + 1 End Sub |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Tried this but its giving me an error when I run the command button on
the form. compile error: Sub or Function not defined The Debugger than highlights "IsNumber" in grey and Function Check2 with Yellow Function check2() As Boolean 'check textbox2 has a 9 digit number If IsNumber |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Ah should have been Isnumeric
On Nov 26, 5:16*pm, macro rewind wrote: Tried this but its giving me an error when I run the command button on the form. compile error: Sub or Function not defined The Debugger than highlights "IsNumber" in grey and Function Check2 with Yellow Function check2() As Boolean 'check textbox2 has a 9 digit number If IsNumber |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Or maybe as Dave Peterson points out
application.isnumber(cell.value) Which is much more stringent than VBA's isnumeric(cell.value) The text string '1234 will return False with excel's =isnumber() worksheet function. Gord Dibben MS Excel MVP On Thu, 26 Nov 2009 09:37:52 -0800 (PST), macro rewind wrote: Ah should have been Isnumeric On Nov 26, 5:16*pm, macro rewind wrote: Tried this but its giving me an error when I run the command button on the form. compile error: Sub or Function not defined The Debugger than highlights "IsNumber" in grey and Function Check2 with Yellow Function check2() As Boolean 'check textbox2 has a 9 digit number If IsNumber |
#6
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I dont understand
1234 is a number in my world why would 'isnumeric' return it as false? More to the point when I use 'isnumber(textbox2.text)' it giving me a compile error:Sub or Function not defined isnumeric isn't another error im getting is, if you delete the data thats written to the sheet by the form it won't let you add anymore data (even if you close and restart excel) Run-time error '1004': Application-defined or object-defined error And the Debugger highlights my line of code that should write the textbox value into the Sheet Cells(y, CLng(Right(tb.Name, 1))) = tb think its getting lost as to what row to add the datainto after the deletion On Nov 26, 6:59*pm, Gord Dibben <gorddibbATshawDOTca wrote: Or maybe as Dave Peterson points out application.isnumber(cell.value) Which is much more stringent than VBA's isnumeric(cell.value) The text string '1234 will return False with excel's =isnumber() worksheet function. Gord Dibben *MS Excel MVP On Thu, 26 Nov 2009 09:37:52 -0800 (PST), macro rewind wrote: Ah should have been Isnumeric On Nov 26, 5:16*pm, macro rewind wrote: Tried this but its giving me an error when I run the command button on the form. compile error: Sub or Function not defined The Debugger than highlights "IsNumber" in grey and Function Check2 with Yellow Function check2() As Boolean 'check textbox2 has a 9 digit number If IsNumber |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Using a Macro in Excel 2004 to move entered data from one sheet toanother and space between rows when next data is entered? | Excel Programming | |||
Developing a macro that will help with mass address cleansing | Excel Programming | |||
interaction with excel and ms SQL (retrieval of records from sql intoa sheet) | Excel Programming | |||
Request for Help in Developing a Macro for a Billing Application | Excel Programming | |||
macro that takes data entered in a user form textbox to go to a ra | Excel Programming |