Solved

Excel Visual Basic Seems to Lose Focus, No Conditional Formatting

Posted on 2014-09-16
3
273 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 45

Expert Comment

by:Martin Liss
Comment Utility
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 20

Accepted Solution

by:
Ejgil Hedegaard earned 500 total points
Comment Utility
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
Comment Utility
Fantastically accurate and helpful.  Many thanks!
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

A short article about a problem I had getting the GPS LocationListener working.
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

771 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

15 Experts available now in Live!

Get 1:1 Help Now