Solved

Excel Visual Basic Seems to Lose Focus, No Conditional Formatting

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

This is about my first experience with programming Arduino.
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

813 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

16 Experts available now in Live!

Get 1:1 Help Now