i need to get rid of this subscript out of range error

  • The line with bold letters shows subscript out of range error

    Admin edit:

    ''error here
    ReDim arr(0 To lastrow - 1, 0 To 4)

    Edited 2 times, last by royUK: ADD CODE TAGS ().

  • Can't really see why you'd get an error, but perhaps try this:

  • In that case maybe you should be putting you last row calculation inside your loop. Try this:

  • Hi,

    Please don't take this as a crtiticism, it's not. I get the when you are still learning everything takes a lot of trial and error. Anyway, I'm not really sure what you are trying to achieve as the code just doesn't seem to make sense to me.

    That being said, I've made a few assumptions as to what is meant to be happening and knocked this up for you. See how it goes. Perhaps best to create a copy before you let vba run wild!

    I've added a few comments, so please read them to make sure you're happy with the assumptions I have made and also confirm to yourself that what you think is happening is actually happening.

  • One little thing. It's definitely not important or neccessary and others may well disagree, but I quite like to be explicit with my input boxes so I can just see from looking at the code what I'm asking for. You can specify a type for the input box (default is text) and if you have a few constants in either your sub or globally you get to have code that is a bit more obvious when you come back to it years later!


  • Thanks a lot!!!!:) the other values need to be copy pasted from another workbook using different macro and a few values as I have mentioned need to be copied from the above sheet to the target sheet based on the id provided.I just need you to get some idea about what I was trying to do with this code because you really made a great effort.thanks again

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!