Inserting Multiple Rows In Very Large Worksheet

bthurman1220

New Member
Joined
Oct 24, 2019
Messages
11
Hoping someone might have some thoughts on optimizing the code below. I am inserting
5 rows each time a new employee is found. Then adding the text for the pay category.

I have done some research and was wondering if "Resize" may be a viable option.

Thanks,

Bob


Code:
X = 2

Do Until Cells(X, 1) = ""




Dim vLoop As Long


    If Cells(X, 10) <> Cells((X + 1), 10) Then
        vLoop = 1
        
        Do While vLoop < 7
        
            Select Case vLoop
            
                Case 1
                    Cells(X, 18) = "BASE SALARY"
                Case 2
                    Cells(X, 18) = "NON-PROFIT BASED BONUS"
                Case 3
                    Cells(X, 18) = "OTHER"
                Case 4
                    Cells(X, 18) = "OVERTIME"
                Case 5
                    Cells(X, 18) = "PROFIT BASED BONUS"
                Case 6
                    Cells(X, 18) = "TOTAL"
                    Exit Do
                    
            End Select
                
            Range(Cells(X, 1), Cells(X, 17)).Select
            Selection.Copy
            Rows(X + 1).Select
            Selection.Insert Shift:=xlDown
            Application.CutCopyMode = False


            vLoop = vLoop + 1
            X = X + 1
            
        Loop
        
        X = X + 1
        
    End If


Loop
 
Does this example work for you?

Perform a test with this data.
ABCDEFGHIJKLMNOPQ
ABCDEFGHIJKLMNOPQ
A2B2C2D2E2F2G2H2I2amorK2L2M2N2O2P2Q2
A3B3C3D3E3F3G3H3I3amorK3L3M3N3O3P3Q3
A4B4C4D4E4F4G4H4I4amorK4L4M4N4O4P4Q4
A5B5C5D5E5F5G5H5I5danteK5L5M5N5O5P5Q5
A6B6C6D6E6F6G6H6I6danteK6L6M6N6O6P6Q6
A7B7C7D7E7F7G7H7I7MenK7L7M7N7O7P7Q7

<tbody>
[TD="align: center"]1[/TD]

[TD="align: center"]2[/TD]

[TD="align: center"]3[/TD]

[TD="align: center"]4[/TD]

[TD="align: center"]5[/TD]

[TD="align: center"]6[/TD]

[TD="align: center"]7[/TD]

</tbody>

If you run the macro more than once the table grows and grows.

Only run the test once and review the results.

------------------------------------------------------------------------------------
If it is not what you need then upload a file to the cloud with 2 sheets on sheet1 you put your original table and on sheet2 you put the expected result.

You could upload a copy of your file to a free site such www.dropbox.com. Once you do that, mark it for 'Sharing' and you will be given a link to the file that you can post here. If the workbook contains confidential information, you could replace it with generic data.

Thank you so much for all your help DanteAmor. Your code will work fine. I was stepping through the code and noticed
that if there were duplicate employee names next to one another then the code was not doing what I wanted. This will not
be an issue because earlier in my code I eliminate all duplicates. Sorry I did not notice this before.

Thank you so much for providing me a solution.

Bob
 
Upvote 0

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
So does it work for you? If it doesn't work, upload an example of your data and the expected result.
 
Upvote 0

Forum statistics

Threads
1,224,818
Messages
6,181,152
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top