LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default problem with an iif() function in a formula

I'm trying to use VBA to put a formula into a range of cells, but something
is not working right.

Here's what I'm trying to accomplish:

I have a list of numbers in column D, beginning in row 2 and ending in row
numRecords, where numRecords is module level variable that contains the row
number of the bottom number in that list in column D. I'm trying to insert
text values to the right of each of those numbers in column E such that:

1. If the number to the immediate left in column D is greater than 0.1,
insert the text string "REG".
2. If the number to the immediate left in column D is less than or equal to
0.1, leave the cell blank.

I've tried using the following code to do this:

Sub enterTP1 numRecords = Range("A1").CurrentRegion.Rows.Count
ActiveSheet.Range(Cells(2, 5), Cells(numRecords, 5)) =
IIf(Range("A1").Cells(2, 4) 0.1, "REG", "")
End Sub

This code almost works, because it inserts the text string "REG" in the
correct range of cells, so there are no problems with my range or cell
specifications or the value or scope of the variable numRows. The problem
is with the evaluation of the iif() function, because my code inserts the
"REG" string in ALL the cells in the range, even where the corresponding
values in column D are less than 0.1. So in effect, the iif() function is
not being evaluated in my code.

Can anyone tell me how to modify my code so it will product the desired
results?

Thanks in advance.

Paul


 
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
Formula / Function Problem TommoUK Excel Discussion (Misc queries) 5 March 25th 08 05:05 AM
Simple problem, simple formula, no FUNCTION ! Ron@Buy Excel Worksheet Functions 6 September 28th 07 04:51 PM
Function problem PE Excel Discussion (Misc queries) 2 April 19th 07 03:36 PM
Problem with IF function.... neilcarden Excel Worksheet Functions 2 March 27th 07 04:32 PM
Problem with IF function [email protected] Excel Discussion (Misc queries) 5 January 19th 06 04:11 PM


All times are GMT +1. The time now is 12:28 AM.

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"