Vba debug line

Last Edited By Krjb Donovan
Last Updated: Mar 05, 2014 10:01 PM GMT

Question

The following code is located in a module in a workbook. It errors out with the debug window. What am I missing? I created it as a macro so that I could call it from within another macro.

It errors on the line: ThisWorkbook.Worksheets("Temp").Range("G3:N3").Select


Sub Clear_OHLC()

ThisWorkbook.Worksheets("Temp").Range("G3:N3").Select
Selection.DeleteContents

End Sub


Answer

It's almost always unnecessary and incorrect to use "select" in code like this. The purpose of your macro is to delete the contents of a range. You don't need to select anything to do this. The code should be:

ThisWorkbook.Worksheets("Temp").Range("G3:N3").ClearContents

Advertisement

©2024 eLuminary LLC. All rights reserved.