automatic row

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I need to reserve rows and columns in a spreadsheet. What I need to do id,
say:

If Row 1, Column 1 has a value, say 2, two rows are to be automatically
reserved. If the value is 1, then 1 column/row is reserved. SOS please.
 
Sub AddRows()
Dim max As Long, i As Long
Dim cnt As Long
max = 10
cnt = 0
i = 1
Do
If IsNumeric(Cells(i, 1)) And Not IsEmpty(Cells(i, 1)) Then
If Cells(i, 1).Value > max Then
max = Cells(i, 1).Value + 1
End If
Cells(i, 1).Offset(1, 0).Resize(Cells(i, 1)).EntireRow.Insert
cnt = 0
Else
If IsEmpty(Cells(i, 1)) Then
cnt = cnt + 1
Else
cnt = 0
End If
End If
i = i + 1
Loop Until cnt > max
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top