View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default Loop or If then Question.

Another way is to plop the formula into all the cells in the range in one fell
swoop. Then clean it up.

Dim myRng As Range
Dim wks As Worksheet
Set wks = Worksheets("somesheethere")
With wks
Set myRng = .Range("d20:d" & .Cells(.Rows.Count, "C").End(xlUp).Row)
With myRng
'plop in the common formula
.FormulaR1C1 = "=vlookup(rc[-1],repinfo,4,0)"

'convert to values
.Value = .Value

'just in case there are no errors
On Error Resume Next
'clean up any errors
.Cells.SpecialCells(xlCellTypeConstants, xlErrors).ClearContents
On Error GoTo 0
End With
End With

I changed the =vlookup() to look for an exact match (4th parm = 0 or False). I
figured with names, you'd want an exact match.


Looping through wrote:

Is there a way to loop thru a list of names and to assign a specific value to
them.

In C20:C1022 is my current list of names and we add to this list everyday. I
want to add a Vlookup formula to the adjasent cell in column D if and only if
a name is present in column C. (=VLOOKUP(R[0]C[-1],RepInfo,4)

Now the twist, after the cell has been assigned a value by the macro, I want
to eliminate the formula and leave the value. Once this is done I want to
move to the next cell and repeat.

The workbook I am doing this in can not have formula inbedded in it because
it is prone to manipulation by other users where one inserted cell the wrong
way will throw all formulas off and the tracking information will not be
accurate.

Any suggestions,
thanks
Peter


--

Dave Peterson