As far as the code it looks fine. I would ask, is it not performing as it should? That's a big difference versus you just want it shorter or written in a different way. If you don't understand the full code you have now, are you going to understand the code better if it is crafted in a different format? Code is very interesting in the fact, not everybody does it the same. Doesn't necessarily mean one is better than the other, just different.
With that being said, based on the comments in this thread, I see you didn't give full credence to the posted comments. Peter and Jack are much more knowledgeable about code than I so I would listen to what they have to say and heed/absorb.
Where is the person who wrote this code, are they not around to ask what they have done?
One of the tools you should consider is
Smart Indenter. This will help make your code much more readable.
The best way to understand your code is by stepping through it by using the F8 key.
Debugging VBA
Open the Excel file which contains this code >> open the VBE >> Alt + F11 >> then select the macro >> press F8 and this will launch the code into the Step Into mode. As you step through by continuing to press F8, the code will advance line by line. Once the line of code has passed a variable, hover your cursor over the variable and you will see the value which is being stored in the variable.
Also, take a look at the link Peter posted and consider getting a VBA book as Jack suggested.
The part where the code is copying and pasting could be cleaned up. Using select in your code can often slow it down. See
here for instructions on how to do it.
Here’s an example:
Code:
Sub Macro1()
Range("A1").Select
Selection.Copy
Range("A2").Select
ActiveSheet.Paste
End Sub
The code above can be rewritten as:
Code:
Range("A1").Copy Destination:=Range("A2")
Finally, please keep all discussions to the public forum. There are many more people out there trying to learn and any advice given will be better served on the open forum. Let’s face it, I am still learning and learn something new on this forum every day. If all those conversation took place through PM’s so much would be lost.
The code you sent me on PM will only be seen by one set of eyes, mine, but on the forum, that same code will be seen by numerous people who only want to help. Remember we all spend our own time on this forum because we love Excel and many who do it much better than I.