Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 99
Default External:=True

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 99
Default External:=True

Hi Carlos,
Your point seems logical to me. I will try it right now and post another
answer later on. Thank you for this quick answer.
By the way, why do you use Call? Why not just xlRng.ClearContents?
Another point: I thought that xlRng.Value = "" was the same as
xlRng.ClearContents. Am I right? I do not want to delete the cells or clear
the formats or anything else, I just want the contents to become a null
string.
Thanks again for your answer. I will sleep better tonight.
--
Jac Tremblay


"Carlos" wrote:

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

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 99
Default External:=True

Hi Carlos,

I did try your code with my application and it works fine. You are a king.

Thanks again.
--
Jac Tremblay


"Carlos" wrote:

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

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 84
Default External:=True

Hi Jac,

1. Use of "Call". You use call (a) when you do not want to store the result
of a function; and (b) when you use parenthesis while writing the arguments
of a macro.

Example of (a). Suppose you've got the function f(x) = x+2. If you just want
to "call" it you say Call f(x), instead of saying y = f(x). This example is
overly simplistic, but I guess building complex examples is not the case here.

Example of (b). Suppose you've got a macro g(x,y). As you mentioned before,
you can say g x, y and it works, but I prefer to call the function in order
to make it clear what arguments does g uses, so I say Call g(x,y).

2. xlRng.Value = "". This differs from ClearContents in that "" is a value:
it is the null string. This value is even one of Excel's constants, the
vbNullString constant. When you say xlRng.Value = "", you are actually
assigning a value to the cells, while when you say xlRng.ClearContents you
are leaving the range blank (without values). By the way, the .Value property
is the default property of a range object, so you don't have to say
xlRng.Value = z, but just xlRng = z.

I know the distinction between vbNullString and ClearContents might not make
the difference for the vast majority of applications. My intention was to
point out that it is different. For example, try filling some cells with the
formula ="" in a blank worksheet. If you move with the keyboard using Ctrl
and the directional arrows (up, down, left and right), you will find that
Excel treats the cells with "" different from blank cells.

--
Carlos


"Jac Tremblay" wrote:

Hi Carlos,
Your point seems logical to me. I will try it right now and post another
answer later on. Thank you for this quick answer.
By the way, why do you use Call? Why not just xlRng.ClearContents?
Another point: I thought that xlRng.Value = "" was the same as
xlRng.ClearContents. Am I right? I do not want to delete the cells or clear
the formats or anything else, I just want the contents to become a null
string.
Thanks again for your answer. I will sleep better tonight.
--
Jac Tremblay


"Carlos" wrote:

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



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default External:=True

I use "Call" only when I'm calling a subroutine that I wrote. I don't usually
use it for my own functions. I'll never use it a builtin VBA function.

And the only difference I've seen between rng.clearcontents and rng.value = ""
is when there is a merged cell in the range. The .clearcontents won't work (as
written). Assigning the value will work.

Jac Tremblay wrote:

Hi Carlos,
Your point seems logical to me. I will try it right now and post another
answer later on. Thank you for this quick answer.
By the way, why do you use Call? Why not just xlRng.ClearContents?
Another point: I thought that xlRng.Value = "" was the same as
xlRng.ClearContents. Am I right? I do not want to delete the cells or clear
the formats or anything else, I just want the contents to become a null
string.
Thanks again for your answer. I will sleep better tonight.
--
Jac Tremblay

"Carlos" wrote:

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


--

Dave Peterson
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 99
Default External:=True

Hi Carlos,
I tested your version of my code and it only works when I just inserted some
data. I does not work on actual data (inserted before).
Here is the code with the problem.
' ***
With rngSuppr
..Range(.Cells(intIndex + 1, 1), _
..Cells(intIndex + 1, intNbCol)).Value = ""
End With
' ***
I patched the problem like thsi but I do not like that solution.
' ***
Dim intK As Integer
With rngSuppr
For intK = 1 To intNbCol
..Cells(intIndex + 1, intK).Value = ""
Next intK
End With
' ***
Would you be able to tell me what the problem is.
Thanks
--
Jac Tremblay


"Carlos" wrote:

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

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Regex Pattern to extract Sheet Name from .Address(external:=True) ExcelMonkey Excel Programming 9 June 4th 08 11:17 AM
What does Address(external:=True) mean? ExcelMonkey Excel Programming 2 June 3rd 08 03:44 PM
Function to return True/False if all are validated as True by ISNU Tetsuya Oguma Excel Worksheet Functions 2 March 15th 06 10:28 AM
When do I need Rng.Address(External:=True) davidm Excel Programming 1 December 22nd 05 12:52 PM
How do I stop Excel from changing the word true to TRUE? Schmyerlou Excel Discussion (Misc queries) 1 November 23rd 05 08:54 PM


All times are GMT +1. The time now is 02:07 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"