Hi,
I get a type mismatch in my code. when i reference to another cell.
What have i tried:
1. I have entered the number that is in the referenced cell manually (see red below). Now the code works fine.
2. In a new excel sheet i have isolated and tested my problem and there i don't get a type mismatch error.
my code that has type mismatch (bolt row)
Dim bankRange As RangeDim rng As Range
Set rng = Range("c:c")
For Each cell In rng
If Int(Left(cell, 2)) = (**51**) Int(Sheets("sheet1").Range("A1")) Then
If bankRange Is Nothing Then
Set bankRange = Union(Range(cell.Address), Range(cell.Offset(0, 1).Address), Range(cell.Offset(0, 2).Address), Range(cell.Offset(0, 3).Address))
Else
Set bankRange = Union(bankRange, Range(cell.Address), Range(cell.Offset(0, 1).Address), Range(cell.Offset(0, 2).Address), Range(cell.Offset(0, 3).Address))
End If
End If
Next
bankRange.Select
bankRange.Copy
This is the code i used in a different workbook and this works fine.
Sub test()
Sheet2.Select
For Each cell In Range("E3")
If Int(Left(cell, 2)) = Int(Sheets("sheet1").Range("A1")) Then
Range("B1") = "True"
Else
Range("B1") = "False"
End If
Next
End Sub
Can somebody help me understand why my main code gives the type mismatch error?
Many thanks
Robert
I get a type mismatch in my code. when i reference to another cell.
What have i tried:
1. I have entered the number that is in the referenced cell manually (see red below). Now the code works fine.
2. In a new excel sheet i have isolated and tested my problem and there i don't get a type mismatch error.
my code that has type mismatch (bolt row)
Dim bankRange As RangeDim rng As Range
Set rng = Range("c:c")
For Each cell In rng
If Int(Left(cell, 2)) = (**51**) Int(Sheets("sheet1").Range("A1")) Then
If bankRange Is Nothing Then
Set bankRange = Union(Range(cell.Address), Range(cell.Offset(0, 1).Address), Range(cell.Offset(0, 2).Address), Range(cell.Offset(0, 3).Address))
Else
Set bankRange = Union(bankRange, Range(cell.Address), Range(cell.Offset(0, 1).Address), Range(cell.Offset(0, 2).Address), Range(cell.Offset(0, 3).Address))
End If
End If
Next
bankRange.Select
bankRange.Copy
This is the code i used in a different workbook and this works fine.
Sub test()
Sheet2.Select
For Each cell In Range("E3")
If Int(Left(cell, 2)) = Int(Sheets("sheet1").Range("A1")) Then
Range("B1") = "True"
Else
Range("B1") = "False"
End If
Next
End Sub
Can somebody help me understand why my main code gives the type mismatch error?
Many thanks
Robert