Thread: External:=True
View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Carlos Carlos is offline
external usenet poster
 
Posts: 84
Default External:=True

Hi Jac, the problem is that when you say Cells(i,j) you are not specifying if
Cells(i,j) belongs to a worksheet or to another range object. Let wks be a
workhseet and xlRng be a range. You should do something like this:

'Note the "." before "Cells(i,j)"
With wks
Set xlRng = .Range(.Cells(1,1),.Cells(10,2))
Call xlRng.ClearContents
End with

If you do not add the dot, Excel does not know what cells are you referring
to. Finally, you should use the ClearContents method instead of assigning the
null string "" to the data range.

The following macro implements this code

Option Explicit
Public Sub subDelete()
'This macro deletes the contants of the range A1:B10
'
'Variables:
'wks = Worksheet "sheet01" of the Active Workbook
'xlRng = A range
'
'
Dim wks As Worksheet
Dim xlRng As Range

'Assign wks
Set wks = ActiveWorkbook.Worksheets("sheet01")

'Assign xlRng (note the "." before Cells)
With wks
Set xlRng = .Range(.Cells(1, 1), .Cells(10, 2))
End With

'There are many operations that apparently look the same, but they aren't.
Call xlRng.ClearContents 'Clear contents
'xlRng = "" 'Every value in the range is set equal to the null string ""
'xlRng.Delete 'The whole range is eliminated from the worksheet

'Clean
Set wks = Nothing
Set xlRng = Nothing

End Sub

--
Carlos


"Jac Tremblay" wrote:

Hi,
I found many posts about the property and I still have a problem with one
statement that bugs because the active sheet is not the one the data is
supposed to be erased from.
rngDelete.Range(Cells(intIndex + 1, 1), _
Cells(intIndex + 1, intNbCol)).Value = ""
I get the error 1004.
When the right sheet is the active one, there is no problem with the code. I
tried to specify the parameter (External:=True) in different places, but I
allways get an error. I seems that it can only be specified after the Address
property.
What should do?
Can someone help me please?
--
Jac Tremblay