VBA If...Then Statement Question

Lochnagar

New Member
Joined
Jan 28, 2008
Messages
43
Hey,

I’m having a little bit of difficultly with the following vba line. <?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:eek:ffice:eek:ffice" /><o:p></o:p>
<o:p> </o:p>
If ActiveCell.Offset(0, -8) = 3 And ActiveCell.Offset(1, -8).Value = 2 Then<o:p></o:p>
<o:p> </o:p>
Basically, when I try and run the code I get a ‘Run-time error ‘13’, Type mismatch’ message/window pop-up and the code terminates. The reason is, at the start, the Activecell.Offset(1,-8).Value line is referring to a cell that contains a piece of text and not a number, however thereafter Activecell.Offset(1,-8).Value always refers to cell containing a number. I thought I could get around this by using an ‘On Error Resume Next’ but that doesn’t seem to work e.g.<o:p></o:p>
<o:p> </o:p>
If ActiveCell.Offset(0, -8) = 3 And ActiveCell.Offset(1, -8).Value = 2 Then<o:p></o:p>
<o:p> </o:p>
On Error Resume Next<o:p></o:p>
<o:p> </o:p>
I appreciate I could get round this using another If..Then statement, but I was hoping that there might be an easier way to get VBA to ignore the error. Any help or suggestions will be very appreciated.<o:p></o:p>
<o:p> </o:p>
Thanks in advance,

Lochnagar<o:p></o:p>
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
The On Error Resume Next line should go BEFORE the line that causes the error

On Error Resume Next

If ActiveCell.Offset(0, -8) = 3 And ActiveCell.Offset(1, -8).Value = 2 Then
 
Upvote 0

Forum statistics

Threads
1,220,965
Messages
6,157,119
Members
451,399
Latest member
alchavar

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top