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
Solved

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

Posted on 2011-02-22
6
7,625 Views
Last Modified: 2012-05-11
hi,
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, _
        SearchOrder:=xlByRows).Row
    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

0
Comment
Question by:intellisource
  • 3
  • 2
6 Comments
 
LVL 10

Expert Comment

by:shahzadbux
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)
                   
0
 
LVL 39

Accepted Solution

by:
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


Thomas
0
 
LVL 39

Expert Comment

by:nutsch
ID: 34953741
@shazadbux: IIF function

T
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 10

Expert Comment

by:shahzadbux
ID: 34953778
Cheers Thomas
0
 

Author Closing Comment

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

Expert Comment

by:nutsch
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).

Thomas
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Outlook Free & Paid Tools
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Learn how to make your own table of contents in Microsoft Word using paragraph styles and the automatic table of contents tool. We'll be using the paragraph styles in Word’s Home toolbar to help you create a table of contents. Type out your initial …
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.

829 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