+ Reply to Thread
Results 1 to 21 of 21

Copying Range Of Numbers Deletes Previously Copied Numbers In Column

  1. #1
    Forum Contributor
    Join Date
    10-29-2019
    Location
    London, England
    MS-Off Ver
    2013
    Posts
    156

    Copying Range Of Numbers Deletes Previously Copied Numbers In Column

    I posted a similar post before, but the script had a lot of irrelevant code. Ive simplified the code for readability. Also if its still not easy to understand, instead of not replying let me know & i'll post a simpler version.

    Basically I need to copy a range of numbers from an array to different cell positions, but it deletes previous copied numbers in that column. ie., copy 1,2,3,4 stored in an array to Range("F37:F52").

    Im guessing I need to resize the array to match the number of values inside it. Ie., 4. But I dont know how to resize it, as I'm new to arrays.

    The line causing the problem is on line 100 : Range(CLabelStartPositionx & ":" & CTotalEndPosition) = Array2

    Thanks.,

    Please Login or Register  to view this content.
    Attached Files Attached Files

  2. #2
    Banned User!
    Join Date
    02-06-2020
    Location
    Iowa City, IA, USA
    MS-Off Ver
    2016 - 365 / 2007
    Posts
    2,014

    Re: Copying Range Of Numbers Deletes Previously Copied Numbers In Column

    what does the error message say? this code of yours:
    Please Login or Register  to view this content.
    I've seen done many times, however I it doesn't make sense that excel would let you throw an entire array's matrix of values into an actual range. it doesn't make any sense to me whatsoever. are you sure you can do that? furthermore, I have seen this done many times too:
    Please Login or Register  to view this content.
    with a ":" in between starting range and ending range. I'm not even sure if that is valid code. but i can't tell you for sure.

  3. #3
    Forum Contributor
    Join Date
    10-29-2019
    Location
    London, England
    MS-Off Ver
    2013
    Posts
    156

    Re: Copying Range Of Numbers Deletes Previously Copied Numbers In Column

    Hi,

    It doesnt create an error, it deletes all of the previous copied numbers in that column, ie., if i copy 1,2,3,4 to Range("F37:F52") using line 100 : Range(CLabelStartPositionx & ":" & CTotalEndPosition) = Array2, it deletes all of the previously copied numbers in column F.

    If you download the attached spreadsheet, it shows this pretty clearly.

    Also it isnt copying all of the array value's, just the values 1,2,3,4 to array2 from array1.
    Last edited by Genus Max; 08-28-2020 at 10:12 PM.

  4. #4
    Banned User!
    Join Date
    02-06-2020
    Location
    Iowa City, IA, USA
    MS-Off Ver
    2016 - 365 / 2007
    Posts
    2,014

    Re: Copying Range Of Numbers Deletes Previously Copied Numbers In Column

    there is an issue with the forum software. uploads are getting corrupted or something. the tech team is trying to fix it. I can't look at your file. upload it to google cloud, share it publicly, and post the link here.

    https://drive.google.com/

    if logged in:

    https://drive.google.com/drive/my-drive

    you're a genius max, you can do that.

  5. #5
    Forum Contributor
    Join Date
    10-29-2019
    Location
    London, England
    MS-Off Ver
    2013
    Posts
    156

    Re: Copying Range Of Numbers Deletes Previously Copied Numbers In Column


  6. #6
    Banned User!
    Join Date
    02-06-2020
    Location
    Iowa City, IA, USA
    MS-Off Ver
    2016 - 365 / 2007
    Posts
    2,014

    Re: Copying Range Of Numbers Deletes Previously Copied Numbers In Column

    ok, so you posted the code that was in the MODULE, not behind the sheet. do any of these images help? do you see what I did here for you?
    Attached Images Attached Images

  7. #7
    Forum Contributor
    Join Date
    10-29-2019
    Location
    London, England
    MS-Off Ver
    2013
    Posts
    156

    Re: Copying Range Of Numbers Deletes Previously Copied Numbers In Column

    Ah, I uploaded the wrong sheet, one sec ill upload the correct, my bad ...

  8. #8
    Banned User!
    Join Date
    02-06-2020
    Location
    Iowa City, IA, USA
    MS-Off Ver
    2016 - 365 / 2007
    Posts
    2,014

    Re: Copying Range Of Numbers Deletes Previously Copied Numbers In Column

    ummmmmmmmmmm

  9. #9
    Forum Contributor
    Join Date
    10-29-2019
    Location
    London, England
    MS-Off Ver
    2013
    Posts
    156

    Re: Copying Range Of Numbers Deletes Previously Copied Numbers In Column


  10. #10
    Forum Contributor
    Join Date
    10-29-2019
    Location
    London, England
    MS-Off Ver
    2013
    Posts
    156

    Re: Copying Range Of Numbers Deletes Previously Copied Numbers In Column

    Basically the script pastes 1,2,3,4 to column F at Range("37:52"). When it pastes 1,2,3,4 a 2nd time to column F at Range("32:36"), it deletes the previous 1,2,3,4 in column F in Range("37:52").
    Last edited by Genus Max; 08-28-2020 at 10:41 PM.

  11. #11
    Banned User!
    Join Date
    02-06-2020
    Location
    Iowa City, IA, USA
    MS-Off Ver
    2016 - 365 / 2007
    Posts
    2,014

    Re: Copying Range Of Numbers Deletes Previously Copied Numbers In Column

    below images:

    1) 1st ITERATION THROUGH ''J'' => result after running the script once with no breakpoints.
    2) 1st ITERATION THROUGH ''J'' => vals of vars CLabelStartPositionx and CTotalEndPosition at time of insertion from array2.
    3) 1st ITERATION THROUGH ''J'' => the result of the offending line of code.
    4) 1st ITERATION THROUGH ''J'' => the reason behind image #3's error-oriented output.
    Attached Images Attached Images

  12. #12
    Banned User!
    Join Date
    02-06-2020
    Location
    Iowa City, IA, USA
    MS-Off Ver
    2016 - 365 / 2007
    Posts
    2,014

    Re: Copying Range Of Numbers Deletes Previously Copied Numbers In Column

    below images:

    1) 2nd ITERATION THROUGH ''J'' => vals of vars CLabelStartPositionx and CTotalEndPosition at time of insertion from array2.
    2) 2nd ITERATION THROUGH ''J'' => the result of the offending line of code.
    3) 2nd ITERATION THROUGH ''J'' => the reason behind image #3's error-oriented output.
    4) 1st ITERATION THROUGH ''J'' => Array1's values received into the matrix.
    5) 1st ITERATION THROUGH ''J'' => Array1's redimensionalization results.
    Attached Images Attached Images

  13. #13
    Banned User!
    Join Date
    02-06-2020
    Location
    Iowa City, IA, USA
    MS-Off Ver
    2016 - 365 / 2007
    Posts
    2,014

    Re: Copying Range Of Numbers Deletes Previously Copied Numbers In Column

    as you can see Max, the reason why the data is disappearing in the cells that you are referring to is because every element in your array after the 4th one is blank. and those values are being thrown to the later cells in the target range. the data is NOT disappearing. you are over-writing it with the new array dimensional data in the later iterations that is blank. the error is in your code.

    with all of the images I posted, do you think you can get it remedied? this is how you solve issues with code. break break break! let us know the result of your fixing efforts.

    https://docs.microsoft.com/en-us/off...rase-statement
    Last edited by vba_php; 08-29-2020 at 12:02 AM.

  14. #14
    Forum Contributor
    Join Date
    10-29-2019
    Location
    London, England
    MS-Off Ver
    2013
    Posts
    156

    Re: Copying Range Of Numbers Deletes Previously Copied Numbers In Column

    Hi,
    Thanks for taking the time, how do I fix it? Im guessing its because of the size of the array, how do i resize the array, so it doesnt overwrite the values?

  15. #15
    Banned User!
    Join Date
    02-06-2020
    Location
    Iowa City, IA, USA
    MS-Off Ver
    2016 - 365 / 2007
    Posts
    2,014

    Re: Copying Range Of Numbers Deletes Previously Copied Numbers In Column

    you responded quickly. did you even look at what I did?

    what's the goal again? your first post isn't detailed enough

  16. #16
    Forum Contributor
    Join Date
    10-29-2019
    Location
    London, England
    MS-Off Ver
    2013
    Posts
    156

    Re: Copying Range Of Numbers Deletes Previously Copied Numbers In Column

    Yes, I looked at what you did. The amount of cells to copy exceeds 4, so it inserts blank cells. I've tried setting the value to match the number of cells to copy but it still inserts blanks, which is why posted on the forum.

  17. #17
    Banned User!
    Join Date
    02-06-2020
    Location
    Iowa City, IA, USA
    MS-Off Ver
    2016 - 365 / 2007
    Posts
    2,014

    Re: Copying Range Of Numbers Deletes Previously Copied Numbers In Column

    yes that's true Max, but have you thoroughly looked at your code line by line? a lot of it doesn't make sense, my man. you are throwing the entire 8000+ (times 2) cells into the array at the beginning and then your doing something else later on that's completely different. is that not correct?

  18. #18
    Forum Contributor
    Join Date
    10-29-2019
    Location
    London, England
    MS-Off Ver
    2013
    Posts
    156

    Re: Copying Range Of Numbers Deletes Previously Copied Numbers In Column

    It doesnt copy the entire range times 2, it resizes array2 to match the size of array1 ...

    Array1 = Range("a1:B8660").Value
    ReDim Array2(1 To UBound(Array1), 1 To UBound(Array1, 2))

  19. #19
    Forum Contributor
    Join Date
    10-29-2019
    Location
    London, England
    MS-Off Ver
    2013
    Posts
    156

    Re: Copying Range Of Numbers Deletes Previously Copied Numbers In Column

    I've fixed the code. Thanks for taking the time, thanks!

  20. #20
    Banned User!
    Join Date
    02-06-2020
    Location
    Iowa City, IA, USA
    MS-Off Ver
    2016 - 365 / 2007
    Posts
    2,014

    Re: Copying Range Of Numbers Deletes Previously Copied Numbers In Column

    good deal. hopefully what I did allowed you to gain insight. and I did NOT say it copies the range times 2. I said this:
    you are throwing the entire 8000+ (times 2) cells into the array at the beginning and then your doing something else later on that's completely different.
    have a good one.

  21. #21
    Forum Contributor
    Join Date
    10-29-2019
    Location
    London, England
    MS-Off Ver
    2013
    Posts
    156

    Re: Copying Range Of Numbers Deletes Previously Copied Numbers In Column

    What did you mean by times 2 then ...

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 6
    Last Post: 11-07-2019, 12:36 PM
  2. Finding a range of numbers in a column of numbers
    By charliemacdmv in forum Excel General
    Replies: 1
    Last Post: 10-17-2019, 09:42 PM
  3. Replies: 4
    Last Post: 10-19-2017, 08:12 AM
  4. Replies: 7
    Last Post: 09-08-2017, 03:24 PM
  5. Replies: 1
    Last Post: 04-26-2015, 01:58 PM
  6. [SOLVED] how to copy and insert copied row basied on numbers in column
    By hazemrezo in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 10-10-2013, 08:19 AM
  7. [SOLVED] Numbers copied from a Double Array to a Range.Value2 loses precision
    By TopXorGuy in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 11-30-2012, 10:19 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1