50 point question on Excel VBA Application defined or object defined error

Posted on 2004-08-16
Medium Priority
Last Modified: 2009-07-29
Please post comments in the original question at http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_21095174.html

Sub CopyTraders()
    Dim Trader As String
    Dim r As Integer
    Dim r2 As Integer
    Dim ColCount As Integer
    Dim rng As Range
     Set rng = ActiveWorkbook.Sheets("layout").UsedRange
    r2 = 5  ''start printing in report at row (5)
    For r = 4 To rng.Rows.Count ''start reading from layout at row (4)
        If rng.Cells(r, 1).value <> "" Then
            Trader = rng.Cells(r, 1).value
           ---> Sheets("report").Cells(r2, ColCount + 2) = Trader             Error occurs in this statement
            ColCount = (ColCount + 1) Mod 4
            If ColCount = 0 Then
                r2 = r2 + 1
            End If
        End If
    Next r
End Sub
Question by:efarhat
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
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 11810819
I haven't worked with Excel much but you can't just pull the "report" Sheet out of thin air...

...but I think it should be:

    ActiveWorkbook.Sheets("report").Cells(r2, ColCount + 2) = Trader



Author Comment

ID: 11811036

that didn't work.
LVL 26

Accepted Solution

EDDYKT earned 80 total points
ID: 11811178
Have you tried

Sheets("report").Cells(r2, ColCount + 2).value  = Trader
LVL 81

Expert Comment

ID: 11817107
I changed this question into a Pointer Question leading to your original question at in the Excel TA. I also refunded 30 of the 50 points in the original value of this question.
byundt--Excel TA Page Editor

Author Comment

ID: 11833936

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month9 days, 21 hours left to enroll

762 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