Advertisement

09.16.2007 at 10:23AM PDT, ID: 22831876
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

9.2

Macro won't run when other workbook is active

Asked by ahammar in Microsoft Office Suite, Microsoft Excel Spreadsheet Software

Tags: ,

Hello experts,
I have a delima.  The following code works fine as long as the worbook that it is in is active.  If I have 2 workbooks open, and the other one is active, it will not work. I get an "Application defined or Object defined error" (Runtime error 1004)
on this line:
Set CopyRange = SearchRange.Cells(x, 1).EntireRow.Range(Cells(1, 1), Cells(1, 11))
I want this macro to run even if a different workbook is active.  
I have tried explicitly naming and referring everything also, but I must be missing something.

Can anyone see what I am missing here?

I tried to rewrite this code so that if you want to duplicate this error, all you need to do is open a new workbook and in Sheet1 put 1's and 2's in column M3 starting in row 3 to whatever row you want.

Like I said it works fine if the workbook is active, but if a different one is active, it will not work.


Sub CopyRows()
Dim ThisWb As Workbook
Dim SearchRange As Range
Dim CopyRange As Range
Dim RowCount As Long
Dim x As Long


Set ThisWb = ThisWorkbook 'I tried changing this to the name of the workbook this code is in, but that didn't work either

Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
    Set SearchRange = ThisWb.Sheets("Sheet1").Range("A1:M36").Columns(13)
    RowCount = SearchRange.Rows.Count
        For x = 3 To RowCount
            If SearchRange.Cells(x, 1).Value = "1" Then
                    If Not CopyRange Is Nothing Then
                        Set CopyRange = Union(CopyRange, SearchRange.Cells(x, 1).EntireRow.Range(Cells(1, 1), Cells(1, 11)))
                    Else
                        Set CopyRange = SearchRange.Cells(x, 1).EntireRow.Range(Cells(1, 1), Cells(1, 11))
                    End If
            End If
        Next x
       
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
End Sub

Any ideas?

:-)
ah
Start Free Trial
[+][-]09.16.2007 at 10:47AM PDT, ID: 19901047

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Microsoft Office Suite, Microsoft Excel Spreadsheet Software
Tags: macro, run
Sign Up Now!
Solution Provided By: sebastienm
Participating Experts: 1
Solution Grade: A
 
 
[+][-]09.16.2007 at 01:06PM PDT, ID: 19901391

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09.16.2007 at 03:34PM PDT, ID: 19901816

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_1_20070628