Inserting missing rows and #s

jimmyrvw

New Member
Joined
May 19, 2011
Messages
2
This is probably a simple bit of coding, but I'm new to VBA and am totally stumped. I work at a homeless shelter and have to make and format rosters numerous times during the day. The program I use for record keeping lets me save records in Excel 2007. If there is no client assigned to a bed the tracking program deletes the whole row, not just the clients name but the bed # also. In this example the macro would have to insert rows and add bed #s for Bed 11, 13 & 20. There are three dorms, one with 26 beds, one at 55 beds and the last has 65 beds. Right now I have to manually do the insertions myself to get the macros used to format printing to work. Please any help will be appreciated. The Name and Bed headers are separate columns




Name Bed
Client a 1
Client x 2
Client l 3
Client b 4
Client q 5
Client w 6
Cliente 7
Client r 8
Client t 9
Client y 10
Client u 12
Client i 14
Client m 15
Client n 16
Client b 17
Client h 18
Client d 19
Client f 21
Client s 22
Client j 23
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
try this macro

Code:
Sub MissingBed()
Dim LR As Long, i As Long
LR = ActiveSheet.Range("A" & Rows.Count).End(xlUp).Row
For i = LR To 2 Step -1
If Cells(i - 1, 2) <> Cells(i, 2) - 1 Then
    Rows(i).EntireRow.Insert
    Cells(i, 2) = Cells(i - 1, 2) + 1
End If
Next i
MsgBox "Done"
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,613
Messages
6,179,903
Members
452,948
Latest member
Dupuhini

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