PC Review


Reply
Thread Tools Rate Thread

Columns("C:C").Value = Columns("D:D").Value not working after adding16th page

 
 
Frank
Guest
Posts: n/a
 
      20th May 2010
I cannot figure this one out.

I have a simple macro which adds 40 new worksheets and retrieves data
on each of these new sheets in column C.

Here is where the code fails

Columns("C:C").Value = Columns("D").Value

It works for 15 sheets but on the 16th, I get the following error
message:

Run-time error '1004':
Application-defined or object-defined error

Any ideas?
 
Reply With Quote
 
 
 
 
Frank
Guest
Posts: n/a
 
      20th May 2010
To add to my post, if I use this code

Range(("C1"), Range("C1").End(xlDown)).Value = Range(("D1"),
Range("D1").End(xlDown)).Value

it works.

But I am still curious why it does not work on a column basis
 
Reply With Quote
 
GS
Guest
Posts: n/a
 
      20th May 2010
It happens that Frank formulated :
> I cannot figure this one out.
>
> I have a simple macro which adds 40 new worksheets and retrieves data
> on each of these new sheets in column C.
>
> Here is where the code fails
>
> Columns("C:C").Value = Columns("D").Value
>
> It works for 15 sheets but on the 16th, I get the following error
> message:
>
> Run-time error '1004':
> Application-defined or object-defined error
>
> Any ideas?


Your code assumes that the target sheet is the active sheet. If you're
adding new sheets, how does Column("D") get values to populate
Column("C:C"). Why not just put the values directly in Column("C:C")?

If the data is stored on a source sheet then you need an object ref to
that sheet. (ie: wksSource) The new sheet would then be the target for
the data and so you need to ref it in the same way. (ie: wksTarget) So
your code should be something like this:

''''''''''
Dim wksSource As Worksheet, wksTarget As Worksheet

Set wksSource =
Workbooks("WbkContainingSourceData").Sheets(WksContainingSourceData")

Set wksTarget = Workbooks("WbkReceivingSourceData").Sheets.Add

wksTarget.Range("C:C") = wksSource.Range("D")
''''''''''

HTH
Garry


 
Reply With Quote
 
Barb Reinhardt
Guest
Posts: n/a
 
      20th May 2010
What is the rest of your code?



"Frank" wrote:

> I cannot figure this one out.
>
> I have a simple macro which adds 40 new worksheets and retrieves data
> on each of these new sheets in column C.
>
> Here is where the code fails
>
> Columns("C:C").Value = Columns("D").Value
>
> It works for 15 sheets but on the 16th, I get the following error
> message:
>
> Run-time error '1004':
> Application-defined or object-defined error
>
> Any ideas?
> .
>

 
Reply With Quote
 
Frank
Guest
Posts: n/a
 
      20th May 2010
the original code was

'remove before and after blanks via TRIM function
Range("D2", Range("C2").End(xlDown).Offset(0, 1)).FormulaR1C1 =
"=TRIM(RC[-1])"
Columns("C:C").Value = Columns("D").Value

I ran the code without the Columns("C:C").Value = Columns("D").Value
and it worked fine
but when included, if fails at the 16th sheet.

I know I could do cell.value = trim(cell).value but I
find .FormulaR1C1 to work faster.
 
Reply With Quote
 
GS
Guest
Posts: n/a
 
      21st May 2010
Frank wrote :
> the original code was
>
> 'remove before and after blanks via TRIM function
> Range("D2", Range("C2").End(xlDown).Offset(0, 1)).FormulaR1C1 =
> "=TRIM(RC[-1])"
> Columns("C:C").Value = Columns("D").Value
>
> I ran the code without the Columns("C:C").Value = Columns("D").Value
> and it worked fine
> but when included, if fails at the 16th sheet.
>
> I know I could do cell.value = trim(cell).value but I
> find .FormulaR1C1 to work faster.


Well, having more info about what you're trying to do certainly helps.
In this case I suggest to just trim the values in "C:C" rather than
enter a formula in "D" to do so and then copy the result back to
"C:C". Doesn't make sense to go to all the trouble when you could use
the VBA Trim() function on the "C:C" cells.

Here's an example:

Sub TrimLeftRightSpaces()
Dim c As Range, lLastRow As Long
lLastRow = ActiveSheet.UsedRange.Rows.Count
For Each c In Range(Cells(1, "C"), Cells(lLastRow, "C"))
If Not c = "" Then c.Value = Trim$(c.Value)
Next
End Sub

HTH
Garry

--
Garry

Free usenet access at http://www.eternal-september.org
ClassicVB Users Regroup! comp.lang.basic.visual.misc


 
Reply With Quote
 
Frank
Guest
Posts: n/a
 
      21st May 2010
Hi Garry:

I thought of that but I find the r1c1 option faster.

I opted for the range.value = range.value and it works.

But it still puzzles me that the column.value = column.value works
fine for 15 sheets and yet fails on the 16th.

Regards,
 
Reply With Quote
 
Helmut Meukel
Guest
Posts: n/a
 
      29th May 2010
"Frank" <(E-Mail Removed)> schrieb im Newsbeitrag
news:3f503742-914a-42cc-9dbc-(E-Mail Removed)...
> Hi Garry:
>
> I thought of that but I find the r1c1 option faster.
>
> I opted for the range.value = range.value and it works.
>
> But it still puzzles me that the column.value = column.value works
> fine for 15 sheets and yet fails on the 16th.
>
> Regards,



Did you try to change the order of the sheets?
What I mean is:
Is it always the 16th sheet regardless which sheet
is the 16th?
Or is it a particular sheet?
I assume it's a particular sheet.
Did you step through all cells of column C and look
for something unusual?
Or is there something in column D far below your last row
which may cause the problem?
I faintly remember I had once - 15 or more years ago -
a problem which I solved by selecting all rows below my
last row and deleting the selection.

Helmut.


 
Reply With Quote
 
Frank
Guest
Posts: n/a
 
      31st May 2010
Hi Helmut:

This is really odd and something's wrong in Excel (I'm using 2003,
maybe this bug as been fixed in later versions)

i = 1
For Each cell In Range("my_range")
i = i + 1
'insert new sheet
Worksheets.Add(After:=Sheet1).Name = "sheet" & i
Columns("C:C").Value = Columns("D").Value
Next

Of course, the above code is useless but it proves that there is an
issue with columns.value = columns.value

You will see it fail when i = 17, therefore on the 16th sheet.

Regards,
 
Reply With Quote
 
GS
Guest
Posts: n/a
 
      31st May 2010
Frank used his keyboard to write :
> Hi Helmut:
>
> This is really odd and something's wrong in Excel (I'm using 2003,
> maybe this bug as been fixed in later versions)
>
> i = 1
> For Each cell In Range("my_range")
> i = i + 1
> 'insert new sheet
> Worksheets.Add(After:=Sheet1).Name = "sheet" & i
> Columns("C:C").Value = Columns("D").Value
> Next
>
> Of course, the above code is useless but it proves that there is an
> issue with columns.value = columns.value
>
> You will see it fail when i = 17, therefore on the 16th sheet.
>
> Regards,


You need to change from using Columns() to using Range().

Example:
Range("C:C") = Range("D")

You don't have to specify value unless the target range is to receive
the product of a formula in the source range. So...

Range("C:C") = Range("D").Value
where the cells in Range("D") contain a formula.

HTH
Garry

--
Garry

Free usenet access at http://www.eternal-september.org
ClassicVB Users Regroup! comp.lang.basic.visual.misc


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
find "Cancellation" in column "A" and copy all data from Columns B-F onto another Sheet bjohnson Microsoft Excel Programming 1 20th Sep 2007 04:02 PM
ReVIEW (Erratum): some shortcut keys not working anymore-----help""""""""PhpApach...WORK WELL!!!! wbrowse@gmail.com Windows XP Help 0 13th Apr 2007 12:29 PM
How to get rid of "duration", "dimension", "quality" columns in explorer JayMore Windows XP Customization 7 3rd Sep 2006 08:21 PM
Excel 2002 "Protect Sheet", but allow "Hide Columns"? =?Utf-8?B?VlAgU2FmZQ==?= Microsoft Excel Worksheet Functions 2 5th Jul 2005 07:13 PM
Method "Columns" of object "IIMEX GRID" failed =?Utf-8?B?RGVzcGVyYXRlIGluIERhbGxhcw==?= Microsoft Access External Data 0 27th Oct 2004 08:55 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:47 AM.