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

I have 5 "rules" in 5 adjacent cells, for example A1, A2,
A3, A4, A5

Each cell contains a formula which displays "Warning" if a
rule is broken, in the corresponding cell
eg if rule 1 is broken A1 will show "Warning" and if rule
4 is broken A4 will show "Warning"

on the next sheet is a cell which is to show which rules
have been broken. So for the example above, it will show
1&4 to show that rules 1 and 4 have been broken.

What I need is some code that will look at each cell and
see if it says "Warning" then I need to put the rule
numbers in the next sheet and separate them if there is
more than on with a &

so far my code is

dim Rule1, Rule2 etc
Rule1 = sheet1.range("a1")
etc

if Rule1 = "Warning" then
sheet2.range("g3") = "1"
end if
if Rule2 = "Warning" then
sheet2.range("g3") = sheet2.range("g3") & "2"
end if

The problem is separating the numbers with an & an leaving
it out if there is only one.

Any help would be much appreciated
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,885
Default cell problem

Hi
not tested but try the following

sub foo()
dim source_wks as worksheet
dim target_wks as worksheet
Dim row_index as long
Dim result

set source_wks=worksheets("Sheet1")
set target_wks=activesheet
for row_index = 1 to 5
if source_wks.cells(row_index,"A").value="Warning" then
if result="" then
result=row_index
else
result=result & "-" & row_index
end if
end if
end if

target_wks.range("B1").value=result
end sub

--
Regards
Frank Kabel
Frankfurt, Germany


Libby wrote:
I have 5 "rules" in 5 adjacent cells, for example A1, A2,
A3, A4, A5

Each cell contains a formula which displays "Warning" if a
rule is broken, in the corresponding cell
eg if rule 1 is broken A1 will show "Warning" and if rule
4 is broken A4 will show "Warning"

on the next sheet is a cell which is to show which rules
have been broken. So for the example above, it will show
1&4 to show that rules 1 and 4 have been broken.

What I need is some code that will look at each cell and
see if it says "Warning" then I need to put the rule
numbers in the next sheet and separate them if there is
more than on with a &

so far my code is

dim Rule1, Rule2 etc
Rule1 = sheet1.range("a1")
etc

if Rule1 = "Warning" then
sheet2.range("g3") = "1"
end if
if Rule2 = "Warning" then
sheet2.range("g3") = sheet2.range("g3") & "2"
end if

The problem is separating the numbers with an & an leaving
it out if there is only one.

Any help would be much appreciated

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
cell problem Techman Excel Discussion (Misc queries) 1 August 26th 08 07:14 PM
Cell Underline problem underlines across width of cell tshoop7 Excel Worksheet Functions 1 July 24th 08 12:18 AM
Last Cell Problem CJN Excel Discussion (Misc queries) 4 November 27th 07 09:53 PM
Very Basic Problem - Merged Cell Equals Contents of a Single Cell jollynicechap Excel Worksheet Functions 3 December 29th 06 08:16 PM
problem with cell reference in =sum(offset(cell reference,x,y,z,a)). Want cell ref to be variable. [email protected] Excel Worksheet Functions 2 December 11th 04 12:05 AM


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

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

About Us

"It's about Microsoft Excel"