Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 25
Default VBA controlled conditional format

Hi,

I'm using a small script to copy a formula down to certain cells based on an
option button selection by the user. For example (this is the code for one
of the option buttons)

Private Sub Opt20_Click()
Dim wks
Set wks = Worksheets("Interface")
wks.Range("f13:f1000").ClearContents
For x = 13 To 32
AccDesc = "=VLOOKUP($E$" & x & " ,[Data.xls]SAP_COA_Map!$D:$E,2)"
wks.Range("f" & x) = AccDesc
Next x
Set wks = Nothing
End Sub

When the user selects this button the formula is copied down and each cell
is calculated and a value is return. The problem here is that the user will
select the button before anything is entered into cell range E:E with the
result that the cells displays "#N/A" because the formula doesn't have
anything to work with.

Using code how do I hide the result in the cell if it is #N/A

Thanks

Paul


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default VBA controlled conditional format

Change your formula to the form

=if(E1="","",Vlookup(E1,F1:G35,2,0))


for the above

activecell.Formula = "=IF(E1="""","""",Vlookup(E1,F1:G35,2,0))"

just to illustrate how you would enter "" inside your string.

--
Regards,
Tom Ogilvy



"Paul" <paulm dot c @ iol dot ie wrote in message
...
Hi,

I'm using a small script to copy a formula down to certain cells based on

an
option button selection by the user. For example (this is the code for one
of the option buttons)

Private Sub Opt20_Click()
Dim wks
Set wks = Worksheets("Interface")
wks.Range("f13:f1000").ClearContents
For x = 13 To 32
AccDesc = "=VLOOKUP($E$" & x & " ,[Data.xls]SAP_COA_Map!$D:$E,2)"
wks.Range("f" & x) = AccDesc
Next x
Set wks = Nothing
End Sub

When the user selects this button the formula is copied down and each cell
is calculated and a value is return. The problem here is that the user

will
select the button before anything is entered into cell range E:E with the
result that the cells displays "#N/A" because the formula doesn't have
anything to work with.

Using code how do I hide the result in the cell if it is #N/A

Thanks

Paul




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 25
Default VBA controlled conditional format

Thanks Tom, Thats fixed it

One more question you might be able to help with. After populating a number
of colums with formulae some fields may return an "#N/A" - in most cases
just simply because there is no data to return. I want to be able to capture
these so I can perform further action if an "#N/A" is found.

I could specify the range in question and loop through each cell then
perform the action if one is found but is there a better way to do this than
looping through each cell individually i.e. can I search the whole worksheet
at once and apply my code as soon as an N/A is found (The code I want to run
is the same no matter where the N/A is found)

Again thanks for your help

Paul

"Tom Ogilvy" wrote in message
...
Change your formula to the form

=if(E1="","",Vlookup(E1,F1:G35,2,0))


for the above

activecell.Formula = "=IF(E1="""","""",Vlookup(E1,F1:G35,2,0))"

just to illustrate how you would enter "" inside your string.

--
Regards,
Tom Ogilvy



"Paul" <paulm dot c @ iol dot ie wrote in message
...
Hi,

I'm using a small script to copy a formula down to certain cells based on

an
option button selection by the user. For example (this is the code for
one
of the option buttons)

Private Sub Opt20_Click()
Dim wks
Set wks = Worksheets("Interface")
wks.Range("f13:f1000").ClearContents
For x = 13 To 32
AccDesc = "=VLOOKUP($E$" & x & " ,[Data.xls]SAP_COA_Map!$D:$E,2)"
wks.Range("f" & x) = AccDesc
Next x
Set wks = Nothing
End Sub

When the user selects this button the formula is copied down and each
cell
is calculated and a value is return. The problem here is that the user

will
select the button before anything is entered into cell range E:E with the
result that the cells displays "#N/A" because the formula doesn't have
anything to work with.

Using code how do I hide the result in the cell if it is #N/A

Thanks

Paul






  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default VBA controlled conditional format

Perhaps something like the below:

Dim rng as Range, cell as Range
On Error Resume Next
set rng = Cells.SpecialCells(xlFormulas,xlErrors)
On Error goto 0
for each cell in rng
if cell.Value = cvErr(xlNa) then


--
Regards,
Tom Ogilvy

"Paul" <paulm dot c @ iol dot ie wrote in message
...
Thanks Tom, Thats fixed it

One more question you might be able to help with. After populating a

number
of colums with formulae some fields may return an "#N/A" - in most cases
just simply because there is no data to return. I want to be able to

capture
these so I can perform further action if an "#N/A" is found.

I could specify the range in question and loop through each cell then
perform the action if one is found but is there a better way to do this

than
looping through each cell individually i.e. can I search the whole

worksheet
at once and apply my code as soon as an N/A is found (The code I want to

run
is the same no matter where the N/A is found)

Again thanks for your help

Paul

"Tom Ogilvy" wrote in message
...
Change your formula to the form

=if(E1="","",Vlookup(E1,F1:G35,2,0))


for the above

activecell.Formula = "=IF(E1="""","""",Vlookup(E1,F1:G35,2,0))"

just to illustrate how you would enter "" inside your string.

--
Regards,
Tom Ogilvy



"Paul" <paulm dot c @ iol dot ie wrote in message
...
Hi,

I'm using a small script to copy a formula down to certain cells based

on
an
option button selection by the user. For example (this is the code for
one
of the option buttons)

Private Sub Opt20_Click()
Dim wks
Set wks = Worksheets("Interface")
wks.Range("f13:f1000").ClearContents
For x = 13 To 32
AccDesc = "=VLOOKUP($E$" & x & " ,[Data.xls]SAP_COA_Map!$D:$E,2)"
wks.Range("f" & x) = AccDesc
Next x
Set wks = Nothing
End Sub

When the user selects this button the formula is copied down and each
cell
is calculated and a value is return. The problem here is that the user

will
select the button before anything is entered into cell range E:E with

the
result that the cells displays "#N/A" because the formula doesn't have
anything to work with.

Using code how do I hide the result in the cell if it is #N/A

Thanks

Paul








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
Independently controlled dates on each worksheet Rick Excel Discussion (Misc queries) 2 January 6th 09 11:55 PM
New Conditional Format Overriding Previous Conditional Format Rene Excel Discussion (Misc queries) 3 February 27th 08 06:08 PM
Can Excel 97 be controlled from VB.NET Nick Dreyer Excel Programming 1 July 21st 05 04:11 PM
Cell Contents controlled via a scroll bar AK Excel Programming 1 April 20th 05 06:58 PM
Cell value controlled by button Zurn[_16_] Excel Programming 2 October 7th 04 02:28 PM


All times are GMT +1. The time now is 11:46 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"