Replace "Expected =" error

tjiddy89

New Member
Joined
Mar 7, 2018
Messages
20
I have an excel spreadsheet that I am trying to remove a substring from the cell and insert into an adjacent cell - mimicking the "Insert Copied Cells" feature in Excel. Problem is that when I try to utilize Replace it gives me "Expected =" as an error. I realize with the current code I would only be able to remove the substring, but I can try to figure out the cut and insert method myself first. Any tips or help would be greatly appreciated.

Code:
Sub fixSheet()

    Dim lRow As Integer, rng As Integer, char As Integer, str As String, totstr As String


    lRow = Cells(Rows.Count, 1).End(xlUp).Row
    
    Worksheets(1).Range("A1:A" & lRow).Select
    
    word = "KB-"


  For Each cell In Selection
  
    char = InStr(cell.Value, word)
        
    If char <> 0 Then
      str = Mid(cell.Value, char)
      totstr = ", " & str
      Replace(cell.value,totstr,"")
      char = 0
      str = ""
    End If
    
  Next cell


End Sub
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
My apologies. I've just realized that I was not assigning the function to a cell which caused the error.
 
Upvote 0

Forum statistics

Threads
1,214,593
Messages
6,120,435
Members
448,961
Latest member
nzskater

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top