ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Error Copying Range/Cell with long Text String (https://www.excelbanter.com/excel-programming/414883-error-copying-range-cell-long-text-string.html)

MikeZz

Error Copying Range/Cell with long Text String
 
Hi
I have a macro that copies a row of data from one workbook to another if it
meets certain criteria.
rngCopy is the range being copied,
rngPaste is the range I where I copy it to.
Each range contains multiple cells.

I get error 1004 when part of the copy range has a cell with a lot of
text... it probably trigger's that error in Excel when you try to copy a cell
which is to many characters. I did notice that it copied all the preceding
cells in the copy range to the paste range and errored out on the first one
that was "to big".

Since I'm using the rngPaste.Value = rngCopy.Value, I don't want to check
the length of each cell before copying.

Is there a way to truncate any cells easily?

Thanks,
MikeZz

Here's the reader's digest of my code causing the error:

Set rngCopy = ManagerFileSht.Range("A" & testRow + r & ":N" & testRow + r)
pasteRow = firstPasteRowClosed + countCopyClosed
Set rngPaste = pasteClosed.Range("C" & pasteRow & ":P" & pasteRow)
rngPaste.Value = rngCopy.Value





joel

Error Copying Range/Cell with long Text String
 
rngPaste.Value = left(rngCopy.Value,256)

"MikeZz" wrote:

Hi
I have a macro that copies a row of data from one workbook to another if it
meets certain criteria.
rngCopy is the range being copied,
rngPaste is the range I where I copy it to.
Each range contains multiple cells.

I get error 1004 when part of the copy range has a cell with a lot of
text... it probably trigger's that error in Excel when you try to copy a cell
which is to many characters. I did notice that it copied all the preceding
cells in the copy range to the paste range and errored out on the first one
that was "to big".

Since I'm using the rngPaste.Value = rngCopy.Value, I don't want to check
the length of each cell before copying.

Is there a way to truncate any cells easily?

Thanks,
MikeZz

Here's the reader's digest of my code causing the error:

Set rngCopy = ManagerFileSht.Range("A" & testRow + r & ":N" & testRow + r)
pasteRow = firstPasteRowClosed + countCopyClosed
Set rngPaste = pasteClosed.Range("C" & pasteRow & ":P" & pasteRow)
rngPaste.Value = rngCopy.Value






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

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com