Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Data Validation

As part of a procedure, I need to check values against those in another
spreadsheet. How do I check values against a range?

For example:

If basebook.Worksheets(1).Cells(rnum, cnum).Value 'is contained within the
range
SiteBook.Worksheets(1).Range("a3:a87") Then

colour the cell green
else colour the cell red

Built in conditional formatting on a list wont work here, as this needs to
run as a procedure is pulling data into the workbook from another (third)
book.

I want to replicate excels data validation on a list using vba, but just
can't get my head around the look up and return true/false bit. Can anyone
offer a suggestion?

Thanks for your time.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,355
Default Data Validation

I presume you've identified basebook and sitebook in your code.

Try something like this:

dim r as range

basebook.Worksheets(1).Cells(rnum, cnum).interior.colorindex = 3
for each r in SiteBook.Worksheets(1).Range("a3:a87")
if r.value = basebook.Worksheets(1).Cells(rnum, cnum).value then
basebook.Worksheets(1).Cells(rnum, cnum).interior.colorindex = 4
exit for
end if
next r

"Astrofin" wrote:

As part of a procedure, I need to check values against those in another
spreadsheet. How do I check values against a range?

For example:

If basebook.Worksheets(1).Cells(rnum, cnum).Value 'is contained within the
range
SiteBook.Worksheets(1).Range("a3:a87") Then

colour the cell green
else colour the cell red

Built in conditional formatting on a list wont work here, as this needs to
run as a procedure is pulling data into the workbook from another (third)
book.

I want to replicate excels data validation on a list using vba, but just
can't get my head around the look up and return true/false bit. Can anyone
offer a suggestion?

Thanks for your time.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Data Validation

Thanks Barb, I've been struggling with this for a while and your solution has
worked perfectly.



"Barb Reinhardt" wrote:

I presume you've identified basebook and sitebook in your code.

Try something like this:

dim r as range

basebook.Worksheets(1).Cells(rnum, cnum).interior.colorindex = 3
for each r in SiteBook.Worksheets(1).Range("a3:a87")
if r.value = basebook.Worksheets(1).Cells(rnum, cnum).value then
basebook.Worksheets(1).Cells(rnum, cnum).interior.colorindex = 4
exit for
end if
next r

"Astrofin" wrote:

As part of a procedure, I need to check values against those in another
spreadsheet. How do I check values against a range?

For example:

If basebook.Worksheets(1).Cells(rnum, cnum).Value 'is contained within the
range
SiteBook.Worksheets(1).Range("a3:a87") Then

colour the cell green
else colour the cell red

Built in conditional formatting on a list wont work here, as this needs to
run as a procedure is pulling data into the workbook from another (third)
book.

I want to replicate excels data validation on a list using vba, but just
can't get my head around the look up and return true/false bit. Can anyone
offer a suggestion?

Thanks for your time.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
custom data validation on cells with data validation values AKrobbins Excel Worksheet Functions 2 June 21st 11 04:20 PM
Validation Data using Validation Table cell range..... Dermot Excel Discussion (Misc queries) 16 January 5th 10 09:35 PM
data validation invalid in dynamic validation list ilia Excel Discussion (Misc queries) 0 November 7th 06 12:54 PM
data validation invalid in dynamic validation list ilia Excel Worksheet Functions 0 November 7th 06 12:54 PM
data validation invalid in dynamic validation list ilia Excel Programming 0 November 7th 06 12:54 PM


All times are GMT +1. The time now is 06:30 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"