View Single Post
  #15   Report Post  
Posted to microsoft.public.excel.programming
keiji kounoike keiji kounoike is offline
external usenet poster
 
Posts: 199
Default if, then, replace text

I don't totally agree with Rick's comment. For example, if all cells in
column P is filled with data and 30000 cells are filled with "CC", then
the loop in Rick's code execute 30000 times and the loop in your code
execute 65536 times (XL 2003). In this case, Rick's code might take more
time than your code. In my thought, the time of procedure depend on
cases. Of course Rick's code looks smarter than yours.

Keiji

FSt1 wrote:
an excelent insight. I learned something. i guess that is why you are an MVP
and we are just the "other guys".
but we do try.

with respects
FSt1

"Rick Rothstein" wrote:

The only problem I see with your code (on a quick look) is that if there are
20,000 rows of data, your loop will execute 20,000 times looking for the
CC's in the column even if there are only, say, 5 CC's in total... the loop
in the code I provided would only execute 5 times.

--
Rick (MVP - Excel)


"ryguy7272" wrote in message
...
I just got help with something a little similar to this yesterday. I made
a
few modifications. What do you think?
Sub Analyze()
Dim lr As Long
lr = Sheets("Sheet1").Cells(Rows.Count, 16).End(xlUp).Row

For Each c In Sheets("Sheet1").Range("P2:P" & lr)
If c.Value = "CC" Then
c.Offset(0, -7).Value = c.Offset(0, -5).Value
End If
Next c
End Sub

HTH,
Ryan---

--
Ryan---
If this information was helpful, please indicate this by clicking ''Yes''.


"Rick Rothstein" wrote:

Give this macro a try (change my Sheet1 reference in the With statement
to
your worksheet's actual name)...

Sub FindCCCopyMarginToMerch()
Dim C As Range
Dim FirstAddress As String
With Worksheets("Sheet1")
Set C = .Columns("P").Find("CC", LookIn:=xlValues, _
LookAt:=xlWhole, MatchCase:=False)
If Not C Is Nothing Then
FirstAddress = C.Address
Do
.Cells(C.Row, "I").Value = .Cells(C.Row, "K").Value
Set C = .Columns("P").FindNext(C)
Loop While Not C Is Nothing And C.Address < FirstAddress
End If
End With
End Sub

--
Rick (MVP - Excel)


"Pam" wrote in message
...
Hi,

I have a worksheet with columns "Merch" (Column I), "Margin" (Column K)
and "Terms" (Column P). What I want to do is, if Terms = CC, replace
Merch
$ amount with Margin $ amount? Is this possible with code?

Any help would be greatly appreciated.
Thanks in advance,
Pam