Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Excel Visual Basic Seems to Lose Focus, No Conditional Formatting

Posted on 2014-09-16
3
Medium Priority
?
282 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 49

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 23

Accepted Solution

by:
Ejgil Hedegaard earned 2000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
Make the most of your online learning experience.
Progress
Introduction to Processes

719 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