custom error messages

R

RussTheBear

I am trying to create a custom error message that evaluates the values of
cells in other columns based on a specific value of one cell in the same row.

This is what I am trying to do:

'First I have to select Column D to measure the amount of rows
'in order to know when to stop

Range("D10").Select
x = ActiveCell.Row
y = ActiveCell.Column
w = 0
Do While Cells(x, y).Value <> ""
x = x + 1
w = w + 1
Loop
Range("A10").Select
x = ActiveCell.Row

'I have to do this until w + 10 because the search starts at 10
'I need to find the value in Column A "#N/A"
'when i find it, I need to make sure there is nothing in the same row of
Column C
'if there is something in Column C, then the error displays
'if there is nothing, then it starts checking the next cell for "#N/A" in
Column A

Do Until x = w + 10

'(the next line of code is where I get the error)

If (Cells(x, 1 = "#N/A") And (Cells(x, 3) <> "") Then
Cells(x, 3).Select
MsgBox "The selected cell SHOULD NOT have a number."
Exit Sub
End If
x = x + 1
Loop

End Sub
 
P

Per Jessen

RussTheBear said:
I am trying to create a custom error message that evaluates the values of
cells in other columns based on a specific value of one cell in the same
row.

This is what I am trying to do:

'First I have to select Column D to measure the amount of rows
'in order to know when to stop

Range("D10").Select
x = ActiveCell.Row
y = ActiveCell.Column
w = 0
Do While Cells(x, y).Value <> ""
x = x + 1
w = w + 1
Loop
Range("A10").Select
x = ActiveCell.Row

'I have to do this until w + 10 because the search starts at 10
'I need to find the value in Column A "#N/A"
'when i find it, I need to make sure there is nothing in the same row of
Column C
'if there is something in Column C, then the error displays
'if there is nothing, then it starts checking the next cell for "#N/A" in
Column A

Do Until x = w + 10

'(the next line of code is where I get the error)

If (Cells(x, 1 = "#N/A") And (Cells(x, 3) <> "") Then
Cells(x, 3).Select
MsgBox "The selected cell SHOULD NOT have a number."
Exit Sub
End If
x = x + 1
Loop

End Sub

Hi

Try something like this.

if cells(x,1).value ="#N/A" and cells(x,3).value <> "" then

Regards,

Per
 
R

RussTheBear

This worked, thank you

If IsError(Cells(x, 1).Value) And Cells(x, 3) <> "" Then
Cells(x, 3).Select
MsgBox "The selected cell SHOULD NOT have a number."
Exit Sub
End If
x = x + 1
Loop
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top