ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Replace (https://www.excelbanter.com/excel-programming/281812-replace.html)

scott[_8_]

Replace
 
I have a macro that does a filter on Column L for Sale Rep "Joe" and
then tries to replace the values in Column A. The problem is that is
replaces all instances in Column A, not just the filtered, or visible cells.

I tried this macro, an some variations, but have not had any success:

Sub UpdateCustType()

Dim mycell As Range
Dim myrng As Range

Set myrng = Range("L2", Selection.End(xlDown)) 'Loop through Sales Reps
For Each mycell In myrng
If Cell.Value = "Joe" Then
Cell.Offset(0, -11).Value = "Ind Contractor"
End If
Next mycell

End Sub

Any help would be appreciated

Thanks,

Scott


Tom Ogilvy

Replace
 
The code you show shouldn't do anything except raise an error since CELL is
not initialized.

Sub UpdateCustType()

Dim mycell As Range
Dim myrng As Range

Set myrng = Range("L2", Range("L2").End(xlDown)) 'Loop through Sales Reps
For Each mycell In myrng
If lcase(myCell.Value) = "joe" Then
myCell.Offset(0, -11).Value = "Ind Contractor"
End If
Next mycell
End Sub

--
Regards,
Tom Ogilvy


"scott" wrote in message
...
I have a macro that does a filter on Column L for Sale Rep "Joe" and
then tries to replace the values in Column A. The problem is that is
replaces all instances in Column A, not just the filtered, or visible

cells.

I tried this macro, an some variations, but have not had any success:

Sub UpdateCustType()

Dim mycell As Range
Dim myrng As Range

Set myrng = Range("L2", Selection.End(xlDown)) 'Loop through Sales Reps
For Each mycell In myrng
If Cell.Value = "Joe" Then
Cell.Offset(0, -11).Value = "Ind Contractor"
End If
Next mycell

End Sub

Any help would be appreciated

Thanks,

Scott





All times are GMT +1. The time now is 03:36 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com