Solved

Excel VBA run time error

Posted on 2013-11-05
4
613 Views
Last Modified: 2013-11-05
When the following statement is executed the error below occurs…
        ColLast = .Cells(4, .Columns.Count).End(xlToLeft).Column
Run-time error ‘424’;
Object required

Can anyone helpwith this?
Thanks in Advance

Code...

Sub UpdateData()
    Dim ColLast As Long, RowLast As Long
    Dim AppendStr As String, Str As String
    Dim RowIndex As Long, ColIndex As Long
   

    With ActiveSheet.Name 'Sheet1
        ColLast = .Cells(4, .Columns.Count).End(xlToLeft).Column
        RowLast = .Cells(.Rows.Count, "D").End(xlUp).Row
        Dim StrArray() As String, i As Integer
               
        For RowIndex = 5 To RowLast
            AppendStr = ""
           
            i = 0
            For ColIndex = 2 To ColLast
                If .Cells(4, ColIndex) = "Regulatory" And .Cells(3, ColIndex).Interior.ColorIndex <> 43 Then
                    Str = .Cells(RowIndex, ColIndex)
                    If i = 0 Then
                        AppendStr = Str
                        ReDim Preserve StrArray(i)
                        StrArray(UBound(StrArray)) = Str
                        i = i + 1
                    ElseIf UBound(Filter(StrArray, Str)) <= -1 Then
                        AppendStr = AppendStr & ", " & Str
                        ReDim Preserve StrArray(i)
                        StrArray(UBound(StrArray)) = Str
                        i = i + 1
                    End If
                End If
            Next ColIndex
           
            .Cells(RowIndex, 1) = AppendStr
        Next RowIndex
       
    End With

End Sub
0
Comment
Question by:tesla764
  • 2
4 Comments
 
LVL 46

Assisted Solution

by:Martin Liss
Martin Liss earned 250 total points
ID: 39624660
Try this:

RowLast  = Cells.Find("*", SearchOrder:=xlByColumns, LookIn:=xlValues, SearchDirection:=xlPrevious).Column
0
 
LVL 35

Accepted Solution

by:
[ fanpages ] earned 250 total points
ID: 39624675
Hi,

...or, change:

With ActiveSheet.Name 'Sheet1

To read:

With ActiveSheet

BFN,

fp.
0
 

Author Closing Comment

by:tesla764
ID: 39624746
Both of these solutions worked.
Thanks everybody.
0
 
LVL 46

Expert Comment

by:Martin Liss
ID: 39624783
You're welcome and I'm glad I was able to help.

Marty - MVP 2009 to 2013
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question