Application-defined or object-defined error

azizrasul

Well-known Member
Joined
Jul 7, 2003
Messages
1,304
Office Version
  1. 365
  2. 2019
  3. 2016
Platform
  1. Windows
I have the following code, where I get the error (Application-defined or object-defined error) on the line

ActiveSheet.Range(Cells(6, z), Cells(10, z)).Select. What am I doing wrong?

Code:
    For Each rng In Range("DateRange")
        If strDateRange <> rng.Value Then
            strDateRange = rng.Value
            Cells(8, 8 + x).Value = rng.Value
            Range(Cells(8, 8 + x), Cells(8, 9 + x)).Select
            Selection.Merge
            Selection.HorizontalAlignment = -4108
            Selection.Font.Bold = True
            Cells(9, 8 + x).Value = "Baseline"
            Cells(10, 8 + x).Value = "Actual"
            Cells(10, 9 + x).Value = "Target"
            Sheets("TARGETS").Select
            ActiveSheet.Cells(5, 3).Select
            For z = 3 To 12
                If ActiveSheet.Cells(5, z) = rng.Value Then
                    ActiveSheet.Range(Cells(6, z), Cells(10, z)).Select
                    Selection.Copy
                    Sheets("KEY PERFORMANCE INDICATORS").Select
                    Cells(11, 9 + x).Select
                    ActiveSheet.Paste
                    Exit For
                End If
            Next z
            x = x + 2
        End If
    Next rng
 
Thanks Norie, that worked, although I can't understand why my original code didn't work. Hmmmmm.

I don't use MS Excel a lot as I am a MS Access man. However I would be grateful if you can tell me why using Select is not good. I normally copy and paste the recorded macro code.
 
Upvote 0

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Aziz

Select just isn't needed but it's probably unqualified references that actually cause the real problems.

Mind you the two seem to go hand in hand and they do affect each other.

I assume at some point you've converted Access macros to VBA?

If you have you'll know that though the code is usually OK it sometimes isn't quite right and you need to change it.

Now in Excel when recording a macro it's the same but it's recording all the actions you take rather than converting existing code.

So you get lots of stuff you just don't need and you need to change a lot more.
 
Upvote 0

Forum statistics

Threads
1,217,383
Messages
6,136,267
Members
450,001
Latest member
KWeekley08

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top