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

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
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,223,164
Messages
6,170,444
Members
452,326
Latest member
johnshaji

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