Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

concatenate error messages

Posted on 2011-04-21
4
Medium Priority
?
206 Views
Last Modified: 2012-05-11
Within a MACRO, if I'm  using seperate IF statements to check the contents of cells for various conditions and writing an error message to a cell for each condition not met, how would I write multiple messages to the same cell if multiple conditions are not met? I'm not looking for the code to test the conditions, just how to write multiple error messages to the same cell (concatenate them)

For example (in plain English), let's say I'm testing a cell in column A as follows and I want to write any error messages to column D

If length of number in column A <> 4 then
   column D = "Invalid length"
end if

If data in column A  is not numeric then
   column D = "data is not numeric"
end if

If date in column A > 1000 then
   column D = "data is greater than 1000"
end if

Now let's say the first two conditions are not met, I want column D to look something like this:

Invalid length, data is not numeric

All I'm trying to do is be able to write multiple error messages to the same cell (when seperate IF statements are used to test each condition)
0
Comment
Question by:dbfromnewjersey
4 Comments
 
LVL 24

Assisted Solution

by:StephenJR
StephenJR earned 200 total points
ID: 35440608
You could do something like this:

 column D =  column D & "Invalid length"
0
 
LVL 85

Accepted Solution

by:
Rory Archibald earned 400 total points
ID: 35440630
Something like:
Dim strMsg as string
If length of number in column A <> 4 then
   strMsg = "Invalid length"
end if

If data in column A  is not numeric then
   strMsg = strMsg & ",data is not numeric"
end if

If date in column A > 1000 then
   strmsg = strmsg ",data is greater than 1000"
end if

if len(strmsg) > 0 then
   if left(strmsg, 1) = "," then
     column D = mid$(strmsg, 2)
   Else
     column D = strmsg
   end if
end if
0
 
LVL 61

Assisted Solution

by:HainKurt
HainKurt earned 400 total points
ID: 35441120
or this
Dim strMsg as string
If length of number in column A <> 4 then
   strMsg = "Invalid length"
end if

If data in column A  is not numeric then
   strMsg = iif(strMsg="","",strMsg & ", ") & "data is not numeric"
end if

If date in column A > 1000 then
   strmsg = iif(strMsg="","",strMsg & ", ") & "data is greater than 1000"
end if

column D = strmsg

Open in new window

0
 

Author Comment

by:dbfromnewjersey
ID: 35441856
Thanks.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
Microsoft's Excel has many features that most people will never need nor take advantage of.  Conditional formatting is one feature that you may find a necessity once you start using it.
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

571 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question