Excel 2010 VBA: Run-time error '32809': Application-Defined or object-Defined error

Posted on 2011-02-22
Medium Priority
Last Modified: 2012-05-11
i am a total newbie regarding writing macros in excel 2010 - the following code which was meant to concatenate the columns 28-30 into 26 for every row in the active sheet using excel 2010 gives the error in the title. i have tried google to find a solution, but to no avail. why is that error being generated in Transposedata()?
the error is displayed on line 8 every time the following code runs:
Sub Transposedata()
    Dim strNotes As String
    Dim r As Integer, c As Integer
    Dim intMax As Integer
    intMax = LastRow(ActiveSheet)
    For r = 2 To intMax Step 1
        For c = 28 To 30 Step 1
            strNotes = IIf(c = 28, ActiveSheet.Cells(r, c).Value, strNotes & strRepeat(vbCrLf, 2) & ActiveSheet.Cells(r, c).Value)
        Next c
        ActiveSheet.Cells(r, 26).Value = strNotes
    Next r
    MsgBox "Done!"
End Sub
Function LastRow(ws As Worksheet) As Single
    'uses worksheet object
    'returns last used row
    On Error Resume Next
    With ws
      LastRow = .Cells.Find(What:="*", _
        SearchDirection:=xlPrevious, _
    End With
End Function
Function strRepeat(str As String, cnt As Integer) As String
    For i = 1 To cnt
        str = str & str
    Next i
End Function

Open in new window

Question by:intellisource
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
LVL 10

Expert Comment

ID: 34953726
Is that a typo on line 8?

two i's for  the if...

strNotes = If(c = 28, ActiveSheet.Cells(r, c).Value, strNotes & strRepeat(vbCrLf, 2) & ActiveSheet.Cells(r, c).Value)
LVL 39

Accepted Solution

nutsch earned 100 total points
ID: 34953731
Define your variables as long instead of integer, integer maxes out after 32 some thousands.

You could speed up the code by avoiding the loop and letting formulas do their job

Sub Transposedata()
    Dim strNotes As String
Dim lastRow As Long
lastRow = Cells(Rows.Count, 28).End(xlUp).Row

Application.ScreenUpdating = False

With Range(Cells(2, 26), Cells(lastRow, 26))
    .FormulaR1C1 = "=RC[2] & char(10) & char(10) & rC[3]& char(10) & char(10) & rC[4] "
    .Value = .Value
End With

Application.ScreenUpdating = True

MsgBox "Done!"
End Sub

Open in new window

LVL 39

Expert Comment

ID: 34953741
@shazadbux: IIF function

Office 365 Training for Admins - 7 Day Trial

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

LVL 10

Expert Comment

ID: 34953778
Cheers Thomas

Author Closing Comment

ID: 34953996
thanks Thomas! this really did the trick ;)
LVL 39

Expert Comment

ID: 34954131
Thanks for the grade.

For reference, because of the VBA knowledge involved, I'd probably price this type of questions around 125 points. It's not overly complicated, but it requires analysis of the code you posted. Since you have unlimited points to ask questions, it's also a way to get faster answers (not that you had to wait long on that one).


Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
If you need to forecast numbers -- typically for finance -- the Windows and Mac versions of Excel 2016 have a basket of tools to get the job done.
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.
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…

770 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