A
Al
I am looking for something that will search col. inputed in an input box,
then check for any of the values that I have in an array, when found, insert
a blank row above it. Here is the code I am using. I am getting an error
message regarding the method can not be used with the range? can some one
help please.
**********************************************
Sub Insert_Row_with_Array()
'This will inseret a row for the selected cell which contains any word
in an array.
'enter only the column letter (without the digit)
'in the input box.
'Keyboard short cut: Ctrl+i
Dim rng As Range, objActiveWkb As Object, objActiveWksht As Object
Dim calcmode As Long
Dim myArr As Variant
Dim I As Long
Dim Message, Title, Default, MyValue
Message = "Enter column letter only" ' Set prompt.
Title = "Delete rows of designated cells" ' Set title.
'Default = "1" ' Set default.
' Display message, title, and default value.
MyValue = InputBox(Message, Title, Default)
'If rng Is Nothing Then
' Exit Sub
' Else
With Application
calcmode = .Calculation
.Calculation = xlCalculationManual
.ScreenUpdating = False
End With
'Fill in the values that you want to delete
myArr = Array("Building", "Building Number", "GSF", "CRV($000's)")
For I = LBound(myArr) To UBound(myArr)
'Sheet with the data, you can also use Sheets("MySheet")
With ActiveSheet
'Firstly, remove the AutoFilter
.AutoFilterMode = False
'Apply the filter
.Range(MyValue & "1:" & MyValue & .Rows.Count).AutoFilter
Field:=1, Criteria1:=myArr(I)
Set rng = Nothing
With .AutoFilter.Range
On Error Resume Next
Set rng = .Offset(1, 0).Resize(.Rows.Count - 1, 1) _
.SpecialCells(xlCellTypeVisible)
On Error GoTo 0
If Not rng Is Nothing Then rng.EntireRow.Insert
End With
'Remove the AutoFilter
.AutoFilterMode = False
End With
Next I
With Application
.ScreenUpdating = True
.Calculation = calcmode
End With
'End If
'ActiveWorkbook.Save
End Sub
**********************************
the statment that is causing the error is:
"rng.EntireRow.Insert"
thanks
Al
then check for any of the values that I have in an array, when found, insert
a blank row above it. Here is the code I am using. I am getting an error
message regarding the method can not be used with the range? can some one
help please.
**********************************************
Sub Insert_Row_with_Array()
'This will inseret a row for the selected cell which contains any word
in an array.
'enter only the column letter (without the digit)
'in the input box.
'Keyboard short cut: Ctrl+i
Dim rng As Range, objActiveWkb As Object, objActiveWksht As Object
Dim calcmode As Long
Dim myArr As Variant
Dim I As Long
Dim Message, Title, Default, MyValue
Message = "Enter column letter only" ' Set prompt.
Title = "Delete rows of designated cells" ' Set title.
'Default = "1" ' Set default.
' Display message, title, and default value.
MyValue = InputBox(Message, Title, Default)
'If rng Is Nothing Then
' Exit Sub
' Else
With Application
calcmode = .Calculation
.Calculation = xlCalculationManual
.ScreenUpdating = False
End With
'Fill in the values that you want to delete
myArr = Array("Building", "Building Number", "GSF", "CRV($000's)")
For I = LBound(myArr) To UBound(myArr)
'Sheet with the data, you can also use Sheets("MySheet")
With ActiveSheet
'Firstly, remove the AutoFilter
.AutoFilterMode = False
'Apply the filter
.Range(MyValue & "1:" & MyValue & .Rows.Count).AutoFilter
Field:=1, Criteria1:=myArr(I)
Set rng = Nothing
With .AutoFilter.Range
On Error Resume Next
Set rng = .Offset(1, 0).Resize(.Rows.Count - 1, 1) _
.SpecialCells(xlCellTypeVisible)
On Error GoTo 0
If Not rng Is Nothing Then rng.EntireRow.Insert
End With
'Remove the AutoFilter
.AutoFilterMode = False
End With
Next I
With Application
.ScreenUpdating = True
.Calculation = calcmode
End With
'End If
'ActiveWorkbook.Save
End Sub
**********************************
the statment that is causing the error is:
"rng.EntireRow.Insert"
thanks
Al