Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 48
Default IsBlank or 6 digits required

On Apr 17, 3:32*pm, Ron wrote:
On Apr 17, 11:55*am, "Rick Rothstein"



wrote:
Two things. First, this...


* * Range("a1")(i, col).Value


can be written more clearly (in my opion) like this...


* * Cells(i, col).Value


The standard way to test this as you would be to do it similar to what
Patrick posted (first changing your Range("a1") to Cells as shown above).
Another way would be like this...


* * If Abs(Len(Cells(i, col).Value)) - 3) = 3 Then
* * * *'
* * * *' *The value is either 0 or 6 characters
* * * *' *long, so execute your code here
* * * *'
* * End If


--
Rick (MVP - Excel)


"Ron" wrote in message


....


Hi all,


How would I edit this line to allow only a blank cell or 6 digits.


If Len(Range("a1")(i, col).Value) < 6 Then


Thank you for your assistance, Ron- Hide quoted text -


- Show quoted text -


Hi guys,
This is the code I'm working with and having a few problems with. *One
problem is getting the input box to respond properly by recognizing
that a cell with no data or if there is data that it is <6 characters
is to be ignored. *If, it has less than 6 or more than 6 *the inputbox
asks for the correct input. Second problem is getting the cancel
button to cancel the process. *The way it's working now is that blank
or empty cells are being recognized but if it has any data it's asking
for the correct input and gets in a loop on the first cell with data
even if the data meets the correct requirement. *Cancel button does
nothing. *Assistance is greatly appreciated, Ron

Sub ValidateDataN()
'validate values in a column
Range("e12").Select
Range(Selection, Selection.End(xlDown)).Offset(0, 9).Select

Set Rng = Selection
FirstRow = Rng.Row
LastRow = Rng.Rows(Rng.Rows.Count).Row
col = "n"
'loop thru col n of database.
For i = FirstRow To LastRow
* * FixColumnN
Next i

End Sub

Private Sub FixColumnN()
Dim x As Integer, OK As Boolean
OK = True
'check to ensure cell is "" or has six digits entered
If IsEmpty(Range("a1")(i, col)) Or Len(Range("a1")(i, col)) = 6 Then
* * OK = False
End If

If OK = False Then
'Enter a new value in Column N
* * Range("a1")(i, col).Select
* * * * Range("a1")(i, col) = InputBox("Please enter a 6 digit value
in *" & ActiveCell.Address & ", *thank you.")

123 * *FixColumnN
End If

Rng.NumberFormat = "@"

End Sub- Hide quoted text -

- Show quoted text -


Hi all,
I've worked out a resolution. All of you suggestions were viable but,
the problem was on my side. I did not have the OK Boolean set
properly. Once I thought the process through I realized that there
was no actions set if OK was true. Here's the solution that I finally
used. I think all suggestions would work with the OK Boolean set
properly. Thank you all for your assistance I learned a lot from you
guys.
Private Sub FixColumnN()
Dim x As Integer, OK As Boolean
OK = False
'check to ensure activecell is "" or six digits entered,
'exceptions handled with the inputbox below.
If Range("a1")(i, col) = "" Or Len(Range("a1")(i, col)) = 6 Then

OK = True
End If

If OK = False Then
'Enter a new value in Column n
Range("a1")(i, col).Select
Range("a1")(i, col) = InputBox("Please enter a 6 digit value
in " & ActiveCell.Address & ", thank you.")

123 FixColumnN

End If

Rng.NumberFormat = "@"

End Sub
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do you change single digits to recognized double digits? Evil with a K[_2_] Excel Worksheet Functions 5 April 3rd 23 02:29 PM
VBA write macro change column with 3 number digits to 4 digits the James C[_2_] Excel Discussion (Misc queries) 3 January 25th 10 03:12 PM
4 digits required for a number Sandeep Excel Worksheet Functions 1 September 9th 08 01:19 AM
Required Field for 7 Numeric digits only LRay67 Excel Programming 33 May 30th 08 03:22 PM
How to customize number to 10 digits including 2 digits after deci Carina Excel Worksheet Functions 3 September 20th 07 02:50 AM


All times are GMT +1. The time now is 09:50 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"