Loop macro, insertion every 12th line & more.

April 7, 2011 at 16:44:35
Specs: Windows XP
Looking for a macro to insert text every 12th line and insert 2 Rows of data(the data is the same and the whole row has to be inserted not just the 1st column, as well as change the first word on the line after the insertion of data. If the word is "or" Change the word to "if" if it is "end" then end, if it is "increase" It will insert text every 15th line and inset 2 lines. or "Decrease" it will go back to every 12 line and inser 2 lines of data. This seems complicated to me and I cant figure it out. I could use some help. This is not urgent I plan on tailoring it for other things I am working on. I just need help getting the core component created. Any help would be appreciated. Thanks.

See More: Loop macro, insertion every 12th line & more.

Report •


#1
April 20, 2011 at 06:25:23
re: "This seems complicated to me..."

Me too! ;-)

Actually, it's not really complicated as much as it's confusing.

You said:

insert text every 12th line and insert 2 Rows of data

Does that mean you actually need to insert 3 rows? One with text and 2 with "data"?

Where is this text and/or data coming from?

"...as well as change the first word on the line after the insertion of data"

What line? Do you mean row? What row...the one with text or the ones with "data".

Perhaps if you post an example of what you are trying to do, before and after, things would be a bit clearer.

Click Here Before Posting Data or VBA Code ---> How To Post Data or Code.


Report •

#2
April 20, 2011 at 06:40:21
Currnetly to get this done. I have 100's of lines of data in sheet 2, I record a macro to Copy 15 lines of data from sheet 2 and paste it to sheet 1. I will try to describe it. I Highlight 15 lines of text , Cntl + C , Cntl PG up, Cntl + V, Cntl + pg down, cntl + pg down, cntl + C on all data from sheet 3(the lines I insert), Cntl + pg up, Cntl + pg up, Cntl + V, Cntl + pg down Delete the 15 lines I have moved already, and start the process over again, I set it up on a hot key to move through all of the data. I heard about VBA being able to do this much easier and allowing more options. So I was just throwing it out there to see if I could get something fairly quickly. And then tailoring it to my exact needs. Thanks.

Report •

#3
April 20, 2011 at 13:05:29
re: "I record a macro to Copy 15 lines of data from sheet 2 and paste it to sheet 1"

and

re: "I heard about VBA being able to do this much easier and allowing more options. "

If you recorded a macro, then you already have VBA code. That's what a macro is: A series of instructions written in the VBA language. Whether recorded via the macro recorder or written manually by typing the instructions into the VBE (VBA Editor) the result is the same: VBA code.

The main difference is that the recorder usually ends up producing some very ineffcient code since it records all your range selections, mouse scrolls, etc. etc. The code will be bloated and hard to read, but can be cleaned up manually by using the VBE.

re: So I was just throwing it out there to see if I could get something fairly quickly. And then tailoring it to my exact needs.

Why not just tailor what you already "wrote" when you recorded the macro by going into the VBE and editing what the recorder produced?

Click Here Before Posting Data or VBA Code ---> How To Post Data or Code.


Report •

Related Solutions

#4
April 20, 2011 at 13:26:54
I wanted the additional things as well, to change between 12 and 15, as well as the logic routine, plus it would be better to push one button and go through all of the code, verse Hotkey all the way through the data. I guess I need to study more, I just was hoping if someone had something similar, with these options I could play with it. I am not advanced in this at all, I have only played with it for a couple of months.

Report •

Ask Question