Forum Discussion
Macros Help Please! I need to delete one word in a cell
This macro does the trick (assuming the files are in a single folder and the items to replace are in a single sheet in each workbook):
Sub RemoveWordItem()
Dim lCount As Long
Dim vFileName As Variant
Dim sPath As String
Dim lFilecount As Long
sPath = "c:\windows\temp\"
ChDrive sPath
ChDir sPath
vFileName = Application.GetOpenFilename("Microsoft Excel files (*.xls*),*.xls*", , "Please select the file(s) to open", , True)
If TypeName(vFileName) = "Boolean" Then Exit Sub
For lCount = LBound(vFileName) To UBound(vFileName)
ProcessFile CStr(vFileName(lCount))
Next
End Sub
Sub ProcessFile(sFileName As String)
Dim oSh As Worksheet
Workbooks.Open sFileName
With ActiveWorkbook.Worksheets("YourSHeetNameGoesHere")
.Range("B:B").Replace What:="items", Replacement:="", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
End With
ActiveWorkbook.Close True
End Sub
Make sure you enter the right sheet name instead of "YourSHeetNameGoesHere"
Hi Jan
I am grateful for your suggestion but it didn't work :-(
I have been trying to use a 'find and replace' type solution within the macro.
Sub itemReplace()
'
' RemoveWordItem Macro
' Remove the words 'item' and 'items' from column B so that only the number remains.
'Variable created which is good practice but not necessary the key here is the wild card *.
Dim itemReplace As String
itemReplace = "item*"
' You can choose however many columns you want from a to zz if you so desire.
Columns("B:B").Select
'itemReplace in the following line is a variable create from the text above.
Selection.Replace What:=itemReplace, Replacement:=" ", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
'
End Sub
this isn't working either!
Any ideas?
- JKPieterseJul 09, 2018Silver ContributorWhat do you mean by "it isn't working" exactly?