Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / September 2007

Tip: Looking for answers? Try searching our database.

Help with insert a row

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Al - 17 Sep 2007 17:14 GMT
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
Bill Renaud - 18 Sep 2007 07:25 GMT
What is the Array in your code?
Array("Building", "Building Number", "GSF", "CRV($000's)")

Is this the list of column labels at the top of your list of data, or
actual values in your list?

If these are column labels (row 1), then the AutoFilter statement inside
your With statement is only filtering a single column, which does not
make sense.
.Range(MyValue & "1:" & MyValue & .Rows.Count).AutoFilter Field:=1,
Criteria1:=myArr(I)

I would suggest adding some variables to set all of your ranges to, then
step through your code and check the locals window to see that they are
set properly. This should help you find the problem. MyValue was set to
a single column (the "MyValue = InputBox(Message, Title, Default)"
statement earlier).

Remember, the easiest way to set a range for an entire list of data
(assuming that it is all that is on the worksheet) is:
Dim rngMyList as Range

Set rngMyList = ActiveSheet.UsedRange

rngMyList.AutoFilter Field:=1, Criteria1:= ....
Signature

Regards,
Bill Renaud

Al - 18 Sep 2007 13:50 GMT
These are column labels that I can use any of them to specify the column. I
really do not need all of them any one will do. These values are repeated
every few rows. Here is a sample of the data in the spread sheet:
********************************************************
Building  Primate Clinic  CRV($000's)  $603     Building Number 504    GSF  2,455   

Subsystem                             Backlog  2008  2009 2010     2011    2012
j.1. Fire Detection Systems     $8         $0     $0     $0     $0     $0
l.1. Interior Finishes                  $0        $0     $0     $0     $0     $32
************************************************************
Here is what the data means:
Building = column lable, Primate Clinic = value, CRV($000's) = column lable,
$603 is the value, Building Number = column lable, 504 = value, GSF = column
lable, 2,455 = value.

Subsystem, Backlog, 2008, 2009, 2010, 2011, 2012 = column lables
the data below them are their values. this pattern repeats in the spread
sheet. not every building will have 2 subsystems, some may have more rows.

Here is what I am trying to accomplish:

I am only interested in "Building" and "Building Number" as lables to be
moved next to the Subsystem, Backlog, 2008, 2009, 2010, 2011, 2012 lables and
then their values moved next to the values of the other lables so that it
should look like this:
*********************************************************
Building    Building Number Subsystem Backlog  2008  2009 2010   2011  2012
Primate Clinic    504          j.1. Fire...   $8         $0     $0     $0     $0  
 $0
                                      l.1. Inte...   $0         $0     $0    
$0     $0     $32
*********************************************************  
the data above is what I want to accomplish eventually, if you have a better
way, I am open. I hope that this is clear and I hope that the format stays
the way I typed it. If you want I can email you the file in excel.
I really appreciate your help. It will help me a lot to get this issue
resolved.
thanks again
Al

> What is the Array in your code?
> Array("Building", "Building Number", "GSF", "CRV($000's)")
[quoted text clipped - 21 lines]
>
> rngMyList.AutoFilter Field:=1, Criteria1:= ....
Al - 18 Sep 2007 14:04 GMT
The lay out got messed up here it is again:
*********************************************************
Building    Building Number Subsystem Backlog  2008  2009 2010   2011  2012
Primate Clinic    504          j.1. Fire...   $8         $0     $0     $0     $0  
 $0
Primate Clinic    504          l.1. Inte...   $0         $0     $0     $0     $0  
 $32
*********************************************************  
Hope this one works
Al

> What is the Array in your code?
> Array("Building", "Building Number", "GSF", "CRV($000's)")
[quoted text clipped - 21 lines]
>
> rngMyList.AutoFilter Field:=1, Criteria1:= ....
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.