Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Formula / Function Problem | Excel Discussion (Misc queries) | |||
Simple problem, simple formula, no FUNCTION ! | Excel Worksheet Functions | |||
Function problem | Excel Discussion (Misc queries) | |||
Problem with IF function.... | Excel Worksheet Functions | |||
Problem with IF function | Excel Discussion (Misc queries) |