Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 284
  • Last Modified:

Excel Visual Basic Seems to Lose Focus, No Conditional Formatting

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
mrherndon
Asked:
mrherndon
1 Solution
 
Martin LissRetired ProgrammerCommented:
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
 
Ejgil HedegaardCommented:
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
 
mrherndonAuthor Commented:
Fantastically accurate and helpful.  Many thanks!
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now