Is this the right approach:- vba to check value in each cell in a range is as expected

chopperj

New Member
Joined
May 5, 2010
Messages
11
hi all, <?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
<o:p></o:p>
I would be grateful if you could give me your view to whether this is the right approach:-<o:p></o:p>
<o:p></o:p>
<o:p></o:p>
There is a current process where many people send in data, in excel, on a monthly basis and this data is meant to be in the same structure, but it is not thus there is lots of tedious work involved of correcting the data. <o:p></o:p>
<o:p></o:p>
I am proposing to standardise the data collection process by sending out a data template with code in, to run once fully populated to review each cell to check that the data is as expected if not high light in red and add error counter to last column ie something like (this is free hand and not meant to read as pure code)-<o:p></o:p>
<o:p></o:p>

(note i thought of simply putting on validation on but some people write the data out but some copy and paste from other sources thus need solution that works regardless of the way the data is populated)<o:p></o:p>

<o:p></o:p>
'----------------------------------------------------------------<o:p></o:p>
sub findRangeLoopRows ()<o:p></o:p>
'headers are in row five<o:p></o:p>
<o:p></o:p>
'Identify full range<o:p></o:p>
bottomrow = range("a65336").end(xlup).row<o:p></o:p>
lastcolumnnum = range ("a5").end(xlright).column <o:p></o:p>
<o:p></o:p>
lastcolumnletter 'then run function to convert column number to column letter<o:p></o:p>
<o:p></o:p>
'loop through each row and run checkrow for each row<o:p></o:p>
for e = 6 to bottomrow<o:p></o:p>
currentrow = ("a" & e & ":" & lastcolumnletter & e)<o:p></o:p>
Checkrow currentrow<o:p></o:p>
<o:p></o:p>
next e<o:p></o:p>
<o:p></o:p>
end sub<o:p></o:p>
<o:p></o:p>
'------------------------------------------------------------<o:p></o:p>
<o:p></o:p>
sub checkrow (currentline as range)<o:p></o:p>
'each column has its own quirks so need to check each one......<o:p></o:p>
<o:p></o:p>
'column A is dates only<o:p></o:p>
if date(currentline.cells(1,1).value) is false then cells(1,1).colour = red<o:p></o:p>
<o:p></o:p>
'column B can only be one from a list of values<o:p></o:p>
if find(currentline.cells(1,2).value) in range ("columnBvalues") is false then cells(1,2).colour = red<o:p></o:p>
<o:p></o:p>
'etc<o:p></o:p>
'etc<o:p></o:p>
'etc<o:p></o:p>
<o:p></o:p>
'Lastly run code to count cells with colour of red colour and if > 1 show error message to advise user not correct by XX number and to review red cells<o:p></o:p>
<o:p></o:p>
'----------------------------------------------------------------------<o:p></o:p>
<o:p></o:p>
<o:p></o:p>
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
In a situation like that, I typically use a Form and never allow the User to see the Workbook. On the Form, I will use ListBoxes or ComboBoxes where possible to limit to entries to only those allowed and Programmatic Data Validation where I have to use a Textbox.
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,849
Members
452,361
Latest member
d3ad3y3

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