Thread
:
Code to replace specific text
View Single Post
#
2
Posted to microsoft.public.excel.programming
Claus Busch
external usenet poster
Posts: 3,872
Code to replace specific text
Hi Steve,
Am Fri, 17 Nov 2017 07:26:27 -0800 (PST) schrieb
:
I'm currently working on a macro that sorts the worksheet by various criteria, and I want to include in the same macro an element of tidying the data so that, if the 'description' cell says 'No Description' (this is from the credit card source data), I'd like to replace it with the content of the corresponding vendor cell:
Col G Col H
Laptop PC Store
No Description PC Store
Keyboard Amazon
becomes
Col G Col H
Laptop PC Store
PC Store PC Store
Keyboard Amazon
try:
Sub ReplaceText()
Dim LRow As Long, i As Long
Dim varData As Variant
With ActiveSheet
LRow = .Cells(.Rows.Count, "G").End(xlUp).Row
varData = .Range("G1:H" & LRow)
For i = LBound(varData) To UBound(varData)
If varData(i, 1) = "No Description" Then
varData(i, 1) = varData(i, 2)
End If
Next
.Range("G1").Resize(UBound(varData), 2) = varData
End With
End Sub
Regards
Claus B.
--
Windows10
Office 2016
Reply With Quote
Claus Busch
View Public Profile
Find all posts by Claus Busch