Replace VBA method

Asked

Viewed 587 times

1

I would like to know how to use the method Replace with dynamic variables in VBA. My line is :

Replace (Cells(endereco(linhaAtual).Row, 22), item.Value, "")

In this case the variable where the String for exchange will be fetched is informed dynamically (endereço is a function created by me and is working perfectly at other times, so I believe the problem is not her), while the value to be replaced is passed through a For Each. In both cases the values are already Strings.

The problem pointed out by Excel is syntax error. Does anyone know what it could be?

  • Tried for each expression in a variable? Ex.: Dim _endereco = endereco(linhaAtual).Row

1 answer

2


I found out. It was very simple. I just needed to assign another variable first. It looks like this:

Cells(endereco(linhaAtual).Row, 19) = Replace(Cells(endereco(linhaAtual).Row, 19), item.Value, "")
  • FWIW: With Cells you will be using the AtiveSheet by default, if there are multiple worksheets in the workbook, it is recommended to set a desired worksheet variable to avoid errors. See this answer to see how to do this.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.