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

Posted on 2011-02-22
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 25 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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

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

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.

Question has a verified solution.

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

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
Outlook for dependable use in a very small business   This article is about using the Outlook application (part of Microsoft Office) in a very small business, or for homeowners where dependability and reliability are critical requirements. This …
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

717 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