Solved

Excel Visual Basic Seems to Lose Focus, No Conditional Formatting

Posted on 2014-09-16
3
276 Views
Last Modified: 2014-09-18
Attached is an Excel file with VB subroutine to advance cells.  Problems I am having are as follows:

1.  Running in Excel 2003, Visual basic sub routine to control cell selection stops working after several entries.  Instead of automatically advancing to the third cell of a row and then, after data entry there, advancing to the first cell of the next row, the sheet will begin skipping from the second cell value to the first cell of the next row.  Or automatically to the first cell of the next row after data being only added to the first cell.
2.  Conditional formatting for the values in the third column do not return in Excel 2003, even though they work properly in Excel 2010.

Details on how the sheet is set so far follow:

From Visual Basic subroutine, when data is entered in the first cell, current time stamp is automatically inserted into second, and when data is entered into the third the focus shifts to the first cell of the next row.

Also, the sheet has a user defined function to calculate time difference based on a range of values, conditional to the third cell entry and the time stamp of the row.

Possible values for C and their time limits before repeat follow:

FREEZER - 1 YEAR
THAW - 1 YEAR
LABEL - 6 MONTHS
QC - 6 MONTHS
5TRASH - 12 HOURS
10TRASH - 12 HOURS
BOOTS - 6 MONTHS
SAFEGLASSES - 3 MONTHS
SAFEVEST - 3 MONTHS
BUMPCAP - 6 MONTHS
FREEZERGLOVES - 1 WEEK
RUBBERGLOVES - 1 WEEK
SANITATION - 6 MONTHS
RETORT - 6 MONTHS
PACKING - 6 MONTHS

Created a array constant as named range DataTable

={"FREEZER",1,"yyyy";"THAW",1,"yyyy";"LABEL",6,"m";"QC",6,"m";"5TRASH",12,"h";"10TRASH",12,"h";"BOOTS",6,"m";"SAFEGLASSES",3,"m";"SAFEVEST",3,"m";"BUMPCAP",6,"m";"FREEZERGLOVES",1,"ww";"RUBBERGLOVES",1,"ww";"SANITATION",6,"m";"RETORT",6,"m";"PACKING",6,"m"}

and used them in the conditional fomatting

please replace the CF formula in C2 with the one in D2

‘=IF(COUNTIF($C$2:$C2,C2)>1,IF(fDateDiff(LARGE((--(($C$2:$C2)=C2)*$B$2:$B2),2),VLOOKUP(C2,DataTable,3),VLOOKUP(C2,DataTable,2))>MAX(--(($C$2:$C2)=C2)*$B$2:$B2),1,0),0)


The formula looks up the data in DataTable to know which time difference to calculate it is processed by the FunctionfDateDiff

I really need some help debugging this code and hope someone can help.
BagRoomV4.xls
0
Comment
Question by:mrherndon
3 Comments
 
LVL 46

Expert Comment

by:Martin Liss
ID: 40328086
I don't have Excel 2003 available to me so I can't investigate the problem myself, but you say you need help with debugging and in that case perhaps this article I wrote on debugging will help.
0
 
LVL 21

Accepted Solution

by:
Ejgil Hedegaard earned 500 total points
ID: 40328946
I can't get the first error.

The conditional formatting does not work because EDate is not part of the VBA worksheet functions in Excel 2003.
So fDateDiff returns an error = no result
Use DateSerial like this

Function fDateDiff(date1, Interval As String, NumberOfTimes As Integer)
    Select Case Interval
        Case "yyyy"
            Res = DateSerial(Year(date1), Month(date1) + 12 * NumberOfTimes, Day(date1))
        Case "m"
            Res = DateSerial(Year(date1), Month(date1) + NumberOfTimes, Day(date1))
        Case "ww"
            Res = date1 + (NumberOfTimes * 7)
        Case "d"
            Res = date1 + NumberOfTimes
        Case "h"
            Res = date1 + NumberOfTimes / 24
        Case Else
            Res = CVErr(xlErrValue)
    End Select
    fDateDiff = Res
End Function

Open in new window

0
 

Author Closing Comment

by:mrherndon
ID: 40330122
Fantastically accurate and helpful.  Many thanks!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

896 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now