View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Bill Renaud Bill Renaud is offline
external usenet poster
 
Posts: 417
Default How to zero out non-contiguous ranges

Hi Dean,

Yes, the problems with mixing code from 2 different authors! Tom did not
declare his variables, and I always use "Option Explicit" at the top of my
code modules, so that is what is producing the "variable not defined
error". The variable "cell" was from his code, which was not defined in my
routine.

Try this version for the Clear routine. It sets the value of the unlocked
cells to zero, rather than clearing each cell. Using ClearContents clears
the cell of all formulas and values, so it will be blank just like a new
worksheet.

Public Sub ClearAandDLoanDrawPercents()
Dim rngCellsToClear As Range
Dim rngCell As Range

Set rngCellsToClear = ThisWorkbook _
.Names("AandDLoanDrawPercents") _
.RefersToRange

For Each rngCell In rngCellsToClear
With rngCell
If Not .Locked Then .Value = 0
End With
Next rngCell
End Sub

I think "Hide_AandD_Rows" should be a separate routine. I don't quite
understand that part yet.
--
Regards,
Bill Renaud