VBA Add new rows based on multiple cell values

Paul1005

New Member
Joined
Dec 27, 2021
Messages
6
Office Version
  1. 2016
Platform
  1. Windows
Hi, I've never written VBA code but based on the forum posts on this site i've been able to create several Macros to my workbook but i'm completley stuck on this last macro i need.

What i'm trying to do is count the number of values within 2 different ranges on sheet 1 & sheet 2
Then calculate the difference and add this number of rows into sheet 2 where there is a value of "ADD" in comuln A

For example if Sheet 1 has 6 cells populated and Sheet 2 has 4 then the difference =2 so i'd like to add 2 rows to Sheet 2 where there is ADD in colum A

Many thanks in advance for any guidance
Paul
 

Attachments

  • sheet 1.PNG
    sheet 1.PNG
    7.4 KB · Views: 7
  • sheet 2.PNG
    sheet 2.PNG
    7.1 KB · Views: 7

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
try this

Sub Add_Rows()
Dim RowDif As Long
RowDif = Sheets("Sheet1").Range("C65000").End(xlUp).Value - Sheets("Sheet2").Range("C65000").End(xlUp).Value
If RowDif = 0 Then Exit Sub
Range(Sheets("Sheet2").Range("C65000").End(xlUp).Offset(-1), Sheets("Sheet2").Range("C65000").End(xlUp).Offset(-1 + RowDif - 1)).EntireRow.Insert
End Sub
 
Upvote 0
Solution
Excellent thanks Sahak works perfectly for my example.
And even better i have been able to use that code within other ranges within other sheets with only minor tweaks
 
Upvote 0

Forum statistics

Threads
1,214,819
Messages
6,121,727
Members
449,049
Latest member
MiguekHeka

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