Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi!
Some years ago, I wrote two VB scripts for Excel in Office 97. Today, I discovered that they no longer work with Excel in Office 2003. Both failures seem to be related to "Cells". Could somebody please help me with how to rewrite the scripts to get rid of the errors? In the first script, I get "Run-time error '1004': Application-defined or object-defined error" for the line "Cells(Row, Column) = 0" in the following script. Does anybody know why I get this error and how to rewrite the code to get rid of it. Unfortunately, I don't remember much about writing Visual Basic scripts. I just did it briefly and it was some years ago. ' ' Diagramdata Makro ' ' Detta makro fyller i de två diagrammen över basaldos i ett testprotokoll efter värdena i ' tabellerna längst upp till vänster på de två sidorna som testprotokollet utgörs av. ' ' Kortkommando: Ctrl+d ' Sub Diagramdata() Dim Row As Integer, Column As Integer Dim Intervall As String Dim FrånTid As Integer, TillTid As Integer Dim Time As Integer Dim i As Integer Row = 6 For Column = 38 To 61 Cells(Row, Column) = 0 Next Column Row = 53 For Column = 38 To 61 Cells(Row, Column) = 0 Next Column For i = 0 To 1 Row = 5 + (47 * i) Intervall = Cells(Row, 1) Do While (Row < 15 + (47 * i) And Intervall < "") Intervall = Cells(Row, 1) FrånTid = Val(Left(Intervall, 2)) TillTid = Val(Right(Intervall, 2)) If TillTid FrånTid Then For Time = FrånTid To TillTid - 1 Cells(6 + (47 * i), 38 + Time) = Cells(Row, 2) Next Time Else For Time = FrånTid To 23 Cells(6 + (47 * i), 38 + Time) = Cells(Row, 2) Next Time For Time = 0 To TillTid - 1 Cells(6 + (47 * i), 38 + Time) = Cells(Row, 2) Next Time End If Row = Row + 1 Intervall = Cells(Row, 1) Loop Next i End Sub In the second script, I get "Run-time error '-2147319784 (80028018)': Automation error Invalid data format" for the line "If Cells(Row, Column) = "Neg" Then". The macro is listed below. Does anybody know how I can modify the script to get it working? ' ' Textfärg Makro ' ' Detta makro går igenom ett testprotokoll och ändrar färgerna på texten för ' urin- och blodsockervärden beroende på hur högt värdet är. ' ' Kortkommando: Ctrl+t ' Sub Textfärg() Dim i As Integer, Row As Integer, Column As Integer Dim Blodsockervärde As Double For i = 0 To 1 For Row = (20 + 47 * i) To (50 + 47 * i) Step 2 For Column = 2 To 4 If Cells(Row, Column) = "Neg" Then Cells(Row, Column).Font.ColorIndex = 10 ElseIf Left(Cells(Row, Column), 1) < "-" And Cells(Row, Column) < "?" And Cells(Row, Column) < "" Then Cells(Row, Column).Font.ColorIndex = 3 Else Cells(Row, Column).Font.ColorIndex = 0 End If Next Column For Column = 5 To 13 If Left(Cells(Row, Column), 1) = "-" Then Cells(Row, Column).Font.ColorIndex = 0 Else If Left(Cells(Row, Column), 2) < "ca" Then Blodsockervärde = CDbl(Cells(Row, Column)) Else Blodsockervärde = CDbl(Right(Cells(Row, Column), Len(Cells(Row, Column)) - 2)) End If If Blodsockervärde <= 4.5 And Blodsockervärde 0 Then Cells(Row, Column).Font.ColorIndex = 5 ElseIf Blodsockervärde = 8.5 Then Cells(Row, Column).Font.ColorIndex = 3 ElseIf Blodsockervärde 4.5 And Blodsockervärde < 8.5 Then Cells(Row, Column).Font.ColorIndex = 10 Else Cells(Row, Column).Font.ColorIndex = 0 End If End If Next Column Next Row Next i End Sub Best Regards, Christian Johansson (change "combort" to "comhem" in my e-mail address if responding via e-mail) |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Trying to work with files copied from Office 2004 (MAC) in Office | Excel Worksheet Functions | |||
Office 2007 compatibility pack on Office 2003 (slow network file | Setting up and Configuration of Excel | |||
Office 2000/Office 2003 Excel not printing landscape vise versa | Setting up and Configuration of Excel | |||
VBA does not work for Office 2003 | Excel Discussion (Misc queries) | |||
Office 2003 - "autocomplete" in file | open or file | save no longer works | Excel Discussion (Misc queries) |