Excel VBA - strange behavior!

Asked

Viewed 72 times

0

Strange behavior in VBA Excel! The code opens a source file, and copies an existing table. Pastes the Table into a target file - in the SUPPORT sheet - and closes the source file. In the destination file there is a spreadsheet named RENTAL, where I return the SUPPORT spreadsheet data - only some data. Before manipulating the data in the RENT spreadsheet, the Cells.Clear command cleans the data in this spreadsheet - RENT, to be able to paste new data:

wsDestino.Range("A3:Z500").Clear

The previous data, of course, were completely deleted, including the formatting, where was also inserted a line-to-line formatting with yes color and no color, using:

wsDestino.Range(Cells(lgLoopLin, "A"), Cells(lgLoopLin, lgUltCol)).Interior.Color = RGB(198, 224, 180)

So far so good. Everything works normally.

But if I unprotect the RENT spreadsheet, select the data, delete with the DELETE key, and the Fill Color icon choose No Fill, and trigger the macro, gives the error "Excel stopped working". Interesting that if I select the data and delete everything manually in the Clean/Clean icon, the error does not happen. It was the impression that, by manually using Fill Color/No Fill, this procedure makes the error happen.

Of course the intention is not to delete manually. I manually deleted the data for testing only. Detail: I use the Application.Screenupdate at the beginning as False, enabling again at the end as True.

inserir a descrição da imagem aqui

inserir a descrição da imagem aqui

  • I never made this mistake, but try disable the JIT debugging or read this ref. You have Visual Studio installed?

  • Visual Studio installed: 2012. But I don’t use it. The interesting thing is that it happens the way I posted it. When I apply the macro it usually follows.

  • And if I delete manually, which is not correct because the macro already does this, but deleting using the Clean/Clean icon, the macro runs normally. I found it interesting the macro to do what it proposes, and only by cleaning the way I mentioned in the post is that the error happens. Remembering again: The data cleaning will NOT be used manually, as the macro already does this.

No answers

Browser other questions tagged

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