Hi,
I'm a total beginner to VBA, so please bear with me if I seem a bit dense.
What I'm Trying to Achieve
I'm trying to write a procedure in Excel, which is supposed to
- look at the pH values stored in column E, row by row
- compare this to a threshold value of 5
- enter a string ("pH range C") in column K, if the value in column E exceeds 5.
The Problem
I'm getting a type mismatch error, as shown in the source code below:
What I think Is Happening
In the sheet "Fal", all data in columns E and K are numeric except for the header row, which is text. I think it is this text that is causing the problem, conflicting with the "Double" variable type I've defined for pH.
My Questions
Any insights gratefully received,
Lara
I'm a total beginner to VBA, so please bear with me if I seem a bit dense.
What I'm Trying to Achieve
I'm trying to write a procedure in Excel, which is supposed to
- look at the pH values stored in column E, row by row
- compare this to a threshold value of 5
- enter a string ("pH range C") in column K, if the value in column E exceeds 5.
The Problem
I'm getting a type mismatch error, as shown in the source code below:
Code:
Sub PNEC()
Dim pH As Double
Dim PNEC As String
Dim usedrows As Double
Dim Row As Integer
usedrows = Worksheets("Fal").UsedRange.Rows.Count
pH = Worksheets("Fal").Columns("E").Value 'TYPE MISMATCH ERROR HERE
PNEC = Worksheets("Fal").Columns("K").Value
For Row = 2 To usedrows Step 1
If pH > 5 Then
PNEC = "pH range C"
End If
Next Row
End Sub
In the sheet "Fal", all data in columns E and K are numeric except for the header row, which is text. I think it is this text that is causing the problem, conflicting with the "Double" variable type I've defined for pH.
My Questions
- Does my diagnosis seem reasonable, or have I misunderstood the problem entirely?
- How can I get around the problem?
Any insights gratefully received,
Lara
Comment