LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 54
Default VBA for data validation in 3rd column does not run. I need help.

I have been able to resolve the problem by several 12 hour days of trial and error. I am posting the solution here in case some others may face a similar difficulty.

I was able to develop a worksheet change macro that functioned, but it was too large for the whole sheet, and I received a 'Procedure Too Large' error.. After some experimentation and with the assistance of two very kind men who helped me (De Primor and Deepak Barnwal) on the Excel-Macros Google Group, I stumbled on a way to split the macro.

This a portion of the two macros that do the data validation, which consists of determining if there is a duplicate in a third column as a result of adding a number in the first column to a number in the second column, in case anyone on this group ever has a similar problem;

Private Sub Worksheet_Change(ByVal Target As Range)

Dim CurrentMessage As String
CurrentMessage = ThisWorkbook.Sheets("Enter Scores").Range("AI32").Value

Select Case True
'

Case Not Intersect(Target, Me.Range("AG68:AG107")) Is Nothing
Call CheckUsed(Target, Me.Range(Target.Address).Value, Me.Range(Target.Address).Offset(0, 1).Value, ("AI68:AI107"))
Case Not Intersect(Target, Me.Range("AH68:AH107")) Is Nothing
Call CheckUsed(Target, Me.Range(Target.Address).Value, Me.Range(Target.Address).Offset(0, -1).Value, ("AI68:AI107"))


Case Not Intersect(Target, Me.Range("AG116:AG135")) Is Nothing
Call CheckUsed(Target, Me.Range(Target.Address).Value, Me.Range(Target.Address).Offset(0, 1).Value, ("AI116:AI135"))
Case Not Intersect(Target, Me.Range("AH116:AH135")) Is Nothing
Call CheckUsed(Target, Me.Range(Target.Address).Value, Me.Range(Target.Address).Offset(0, -1).Value, ("AI116:AI135"))

' etc, for all of my groupings...

End Select
Application.EnableEvents = True
End Sub

' The following sub was developed just to keep the first sub from being to large for Excel to process. I did not know there was a limit, but of course, at first I exceeded it. I believe it is somewhere around 56K when compiled. Of course, I had no idea how large it would be when compiled (and I still don't really know), but I knew I had to split it somehow because I kept getting the error messages. Again by trial and error, and with their guidance, I figured out where I could split it up with the second sub below;

Private Sub CheckUsed(ByVal Target As Range, ByVal aadress As Variant, ByVal aadressoffset As Variant, ByVal Rng As String)
Application.EnableEvents = False
Dim CurrentMessage As String
CurrentMessage = Range("AI32").Value
If Application.CountIf(Range(Rng), (aadress + aadressoffset)) 1 Then If MsgBox(CurrentMessage, vbYesNo + vbQuestion, "[Personal Heading - insert your own if you copy this code]") = vbNo Then Range(Target.Address).Value = ""

End Sub

I still have not figured out why Excel's built-in data validation is not consistent in giving me a valid result with either validation forumla '=if(Countif($C$1:$C$20,$A1+$B1)<=1,"True","False" )' or 'Countif($C$1:$C:20,)$A1+$B1))<=1' - I don't know if both of my attempts at a validation formula were not correct or what the problem was. My problem started when Excel 2007 came out - prior to that they seemed to work fine. After Excel 2007, sometimes one of these works at detecting a duplicate, sometimes neither one works at detecting a duplicate, and sometimes I get a nuisance error message when there was no duplicate. Going to VBA for my data validation has eliminated the problem, as far as I can tell anyway. If someone knows why neither of these formulas worked reliably in Excel2007 and later, I would appreciate knowing to increase my understanding of Excel. But for now, my problem has been solved.

Best wishes to all on the group.
 
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
Using Table Column for Data Validation List keith Excel Discussion (Misc queries) 9 April 2nd 23 08:55 PM
Data Validation - lists if certain column is certain value George Excel Programming 2 October 22nd 07 12:38 PM
Dependant Data Validation - for Whole Column Kumaresh Sierra Excel Worksheet Functions 2 July 10th 07 09:32 AM
Loading Column Data with blank Rows into Data Validation Box ExcelMonkey Excel Worksheet Functions 3 October 13th 05 06:09 PM
Multi column Data Validation List Chris Excel Programming 1 September 17th 03 04:20 AM


All times are GMT +1. The time now is 09:10 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"