Sie sind auf Seite 1von 5

a)

Sub InsertTwoBlankRows()

'Step1: Declare variables.

Dim MyRange As Range

Dim iCounter As Long

'Step 2: Define the target Range, using the named range, "YearlySales"

Set MyRange = Range("YearlySales")

'Step 3: Start reverse looping through the range.

For iCounter = MyRange.Rows.Count To 2 Step -1

'Step 4: Insert two blank rows.

MyRange.Rows(iCounter).EntireRow.Insert

MyRange.Rows(iCounter).EntireRow.Insert

'Step 5: Increment the counter down

Next iCounter

End Sub

Delete rows

Sub DeleteBlankRows()
'Step1: Declare variables.

Dim MyRange As Range

Dim iCounter As Long

'Step 2: Define the target Range, by utilizing the UsedRange property

Set MyRange = ActiveSheet.UsedRange

'Step 3: Start reverse looping through the range.

For iCounter = MyRange.Rows.Count To 1 Step -1

'Step 4: If entire row is empty, then delete it.

If Application.CountA(Rows(iCounter).EntireRow) = 0 Then

Rows(iCounter).Delete

End If

'Step 5: Increment the counter down

Next iCounter

End Sub

Dim retry As Double

retry = MsgBox("Do you want to retry with another value?", vbYesNo)

If retry = vbYes Then GoTo RepeatProc

If retry = vbNo Then

MsgBox ("Thanking You..")

End If
Option Explicit

Sub InsertNBlankRows()

'Step1: Declare variables.

Dim MyRange As Range

Dim iCounter As Long

Dim BRowCount As Integer

ErrorHandler:

'Step 2: Define the target Range, using the named range, "YearlySales"

Set MyRange = Range("SalesRange")

On Error GoTo ErrorHandler

'Step 3: Prompt User for number of blank rows

BRowCount = InputBox("Insert 1,2 or 3 Blank Rows?")

'Step 4: Start reverse looping through the range.

For iCounter = MyRange.Rows.Count To 2 Step -1

'Step 5: Insert one,two,three blank rows.

If BRowCount = 1 Then

MyRange.Rows(iCounter).EntireRow.Insert

ElseIf BRowCount = 2 Then

MyRange.Rows(iCounter).EntireRow.Insert

MyRange.Rows(iCounter).EntireRow.Insert

ElseIf BRowCount = 3 Then

MyRange.Rows(iCounter).EntireRow.Insert
MyRange.Rows(iCounter).EntireRow.Insert

MyRange.Rows(iCounter).EntireRow.Insert

Else

MsgBox "Enter Eiether 1, 2 or 3 blank rows only"

End If

'Step 6: Increment the counter down

Next iCounter

MsgBox "Thank You"

End Sub

Sub ApplyColorBanding()

'Step1: Declare variables.

Dim MyRange As Range

Dim MyRow As Range

'Step 2: Define the target Range, by selecting a range of cells

Set MyRange = ActiveSheet.UsedRange

'Step 3: Start looping through the selected range.

For Each MyRow In MyRange.Rows

'Step 4: Check if the row is an even number.

If MyRow.Row Mod 2 = 0 Then

'Step 5: Apply appropriate alternate color.


MyRow.Interior.ColorIndex = 35

Else

MyRow.Interior.ColorIndex = 2

End If

'Step 6: Loop back to get next row.

Next MyRow

End Sub

If BRowCount = 1 Then

MyRange.Rows(iCounter).EntireRow.Insert

ElseIf BRowCount = 2 Then

MyRange.Rows(iCounter).EntireRow.Insert

MyRange.Rows(iCounter).EntireRow.Insert

ElseIf BRowCount = 3 Then

MyRange.Rows(iCounter).EntireRow.Insert

MyRange.Rows(iCounter).EntireRow.Insert

MyRange.Rows(iCounter).EntireRow.Insert

End If

Das könnte Ihnen auch gefallen