+ Reply to Thread
Results 1 to 8 of 8

error: ActiveCell.Offset(0, -1).Select = Application-defined or object-defined error

  1. #1
    -[::::Shamran::::]-
    Guest

    error: ActiveCell.Offset(0, -1).Select = Application-defined or object-defined error

    Why do I keep getting 1004 error when trying to move active cell ?? :

    For a = 1 To 6000
    If ActiveCell = "F" Then 'Sortering for kvinder og 20-39 år

    ActiveCell.Offset(0, -1).Select ' Flyt activ celle til alder

    If ActiveCell >= 20 And ActiveCell >= 39 Then

    ActiveCell.Offset(0, 12).Select ' Flyt activ celle til fedtprocent

    If ActiveCell < 21 Then
    myCount = Sheets("Fedtprocent").Range("C12") + 1
    Sheets("Fedtprocent").Range("C12") = myCount
    End If

    If ActiveCell >= 21 And ActiveCell < 33 Then
    myCount = Sheets("Fedtprocent").Range("C13") + 1
    Sheets("Fedtprocent").Range("C13") = myCount
    End If

    If ActiveCell >= 33 And ActiveCell < 39 Then
    myCount = Sheets("Fedtprocent").Range("C14") + 1
    Sheets("Fedtprocent").Range("C14") = myCount
    End If

    If ActiveCell >= 39 Then
    myCount = Sheets("Fedtprocent").Range("C15") + 1
    Sheets("Fedtprocent").Range("C15") = myCount
    End If

    End If

    End If

    If ActiveCell.Value = "" Then 'End macro ved tom celle
    Sheets("Fedtprocent").Select
    Range("L2").Select
    Application.ScreenUpdating = True
    End
    End If

    ActiveCell.Offset(1, -11).Select ' Flyt celle ned. Fedtprocent celle er
    valgt <------------ERROR !

    Next a


    Regards Shamran



  2. #2
    Tushar Mehta
    Guest

    Re: error: ActiveCell.Offset(0, -1).Select = Application-defined or object-defined error

    What is the active cell when you get the error? With that as the=20
    activecell, what would it mean to move 11 columns to the left?

    --=20
    Regards,

    Tushar Mehta
    www.tushar-mehta.com
    Excel, PowerPoint, and VBA add-ins, tutorials
    Custom MS Office productivity solutions

    In article <[email protected]>,=20
    [email protected] says...
    > Why do I keep getting 1004 error when trying to move active cell ?? :
    >=20
    > For a =3D 1 To 6000
    > If ActiveCell =3D "F" Then 'Sortering for kvinder og 20-39 =E5r
    >=20
    > ActiveCell.Offset(0, -1).Select ' Flyt activ celle til alder
    >=20
    > If ActiveCell >=3D 20 And ActiveCell >=3D 39 Then
    >=20
    > ActiveCell.Offset(0, 12).Select ' Flyt activ celle til fedtproce=

    nt
    >=20
    > If ActiveCell < 21 Then
    > myCount =3D Sheets("Fedtprocent").Range("C12") + 1
    > Sheets("Fedtprocent").Range("C12") =3D myCount
    > End If
    >=20
    > If ActiveCell >=3D 21 And ActiveCell < 33 Then
    > myCount =3D Sheets("Fedtprocent").Range("C13") + 1
    > Sheets("Fedtprocent").Range("C13") =3D myCount
    > End If
    >=20
    > If ActiveCell >=3D 33 And ActiveCell < 39 Then
    > myCount =3D Sheets("Fedtprocent").Range("C14") + 1
    > Sheets("Fedtprocent").Range("C14") =3D myCount
    > End If
    >=20
    > If ActiveCell >=3D 39 Then
    > myCount =3D Sheets("Fedtprocent").Range("C15") + 1
    > Sheets("Fedtprocent").Range("C15") =3D myCount
    > End If
    >=20
    > End If
    >=20
    > End If
    >=20
    > If ActiveCell.Value =3D "" Then 'End macro ved tom celle
    > Sheets("Fedtprocent").Select
    > Range("L2").Select
    > Application.ScreenUpdating =3D True
    > End
    > End If
    >=20
    > ActiveCell.Offset(1, -11).Select ' Flyt celle ned. Fedtprocent celle er=

    =20
    > valgt <------------ERROR !
    >=20
    > Next a
    >=20
    >=20
    > Regards Shamran=20
    >=20
    >=20
    >=20


  3. #3
    Tom Ogilvy
    Guest

    Re: error: ActiveCell.Offset(0, -1).Select = Application-defined or object-defined error

    Probably because you have that statement in the wrong place and going -11
    goes off the sheet. I suspect it should only be executed if the command
    ActiveCell.Offset(0, 12).Select ' Flyt activ celle til fedtprocent

    has been executed - but that requires passing two IF statemetns to get
    there. The Move back is outside those if statements - so it is executed on
    every loop.

    --
    Regards,
    Tom Ogilvy


    "-[::::Shamran::::]-" <[email protected]> wrote in message
    news:[email protected]...
    > Why do I keep getting 1004 error when trying to move active cell ?? :
    >
    > For a = 1 To 6000
    > If ActiveCell = "F" Then 'Sortering for kvinder og 20-39 år
    >
    > ActiveCell.Offset(0, -1).Select ' Flyt activ celle til alder
    >
    > If ActiveCell >= 20 And ActiveCell >= 39 Then
    >
    > ActiveCell.Offset(0, 12).Select ' Flyt activ celle til

    fedtprocent
    >
    > If ActiveCell < 21 Then
    > myCount = Sheets("Fedtprocent").Range("C12") + 1
    > Sheets("Fedtprocent").Range("C12") = myCount
    > End If
    >
    > If ActiveCell >= 21 And ActiveCell < 33 Then
    > myCount = Sheets("Fedtprocent").Range("C13") + 1
    > Sheets("Fedtprocent").Range("C13") = myCount
    > End If
    >
    > If ActiveCell >= 33 And ActiveCell < 39 Then
    > myCount = Sheets("Fedtprocent").Range("C14") + 1
    > Sheets("Fedtprocent").Range("C14") = myCount
    > End If
    >
    > If ActiveCell >= 39 Then
    > myCount = Sheets("Fedtprocent").Range("C15") + 1
    > Sheets("Fedtprocent").Range("C15") = myCount
    > End If
    >
    > End If
    >
    > End If
    >
    > If ActiveCell.Value = "" Then 'End macro ved tom celle
    > Sheets("Fedtprocent").Select
    > Range("L2").Select
    > Application.ScreenUpdating = True
    > End
    > End If
    >
    > ActiveCell.Offset(1, -11).Select ' Flyt celle ned. Fedtprocent celle er
    > valgt <------------ERROR !
    >
    > Next a
    >
    >
    > Regards Shamran
    >
    >




  4. #4
    -[::::Shamran::::]-
    Guest

    Re: error: ActiveCell.Offset(0, -1).Select = Application-defined or object-defined error

    Strange ... I don't think that I am going off the Sheet :

    The full code looks like this :

    Sub Fedtprocent()

    Sheets("data").Select
    Range("O2").Select
    ActiveCell.Offset(0, -11).Select 'Flytter aktivcelle til køn

    For a = 1 To 6000

    If ActiveCell = "F" Then 'Sortering for kvinder og 20-39 år

    ActiveCell.Offset(0, -1).Select ' Flyt activ celle til alder

    If ActiveCell >= 20 And ActiveCell >= 39 Then

    ActiveCell.Offset(0, 12).Select ' Flyt activ celle til fedtprocent

    If ActiveCell < 21 Then
    myCount = Sheets("Fedtprocent").Range("C12") + 1
    Sheets("Fedtprocent").Range("C12") = myCount
    End If

    If ActiveCell >= 21 And ActiveCell < 33 Then
    myCount = Sheets("Fedtprocent").Range("C13") + 1
    Sheets("Fedtprocent").Range("C13") = myCount
    End If

    If ActiveCell >= 33 And ActiveCell < 39 Then
    myCount = Sheets("Fedtprocent").Range("C14") + 1
    Sheets("Fedtprocent").Range("C14") = myCount
    End If

    If ActiveCell >= 39 Then
    myCount = Sheets("Fedtprocent").Range("C15") + 1
    Sheets("Fedtprocent").Range("C15") = myCount
    End If

    End If

    End If


    If ActiveCell.Value = "" Then 'End macro ved tom celle
    Sheets("Fedtprocent").Select
    Range("L2").Select
    Application.ScreenUpdating = True
    End
    End If

    ActiveCell.Offset(1, -11).Select ' Flyt celle ned. Fedtprocent celle er
    valgt

    Next a

    End Sub




  5. #5
    Dave Peterson
    Guest

    Re: error: ActiveCell.Offset(0, -1).Select = Application-defined orobject-defined error

    Excel has 256 columns.

    You're running a loop from 1 to 6000 that tries to move one column to the left:
    ActiveCell.Offset(0, -1).Select

    it should blow up pretty early in the loop.

    "-[::::Shamran::::]-" wrote:
    >
    > Why do I keep getting 1004 error when trying to move active cell ?? :
    >
    > For a = 1 To 6000
    > If ActiveCell = "F" Then 'Sortering for kvinder og 20-39 år
    >
    > ActiveCell.Offset(0, -1).Select ' Flyt activ celle til alder
    >
    > If ActiveCell >= 20 And ActiveCell >= 39 Then
    >
    > ActiveCell.Offset(0, 12).Select ' Flyt activ celle til fedtprocent
    >
    > If ActiveCell < 21 Then
    > myCount = Sheets("Fedtprocent").Range("C12") + 1
    > Sheets("Fedtprocent").Range("C12") = myCount
    > End If
    >
    > If ActiveCell >= 21 And ActiveCell < 33 Then
    > myCount = Sheets("Fedtprocent").Range("C13") + 1
    > Sheets("Fedtprocent").Range("C13") = myCount
    > End If
    >
    > If ActiveCell >= 33 And ActiveCell < 39 Then
    > myCount = Sheets("Fedtprocent").Range("C14") + 1
    > Sheets("Fedtprocent").Range("C14") = myCount
    > End If
    >
    > If ActiveCell >= 39 Then
    > myCount = Sheets("Fedtprocent").Range("C15") + 1
    > Sheets("Fedtprocent").Range("C15") = myCount
    > End If
    >
    > End If
    >
    > End If
    >
    > If ActiveCell.Value = "" Then 'End macro ved tom celle
    > Sheets("Fedtprocent").Select
    > Range("L2").Select
    > Application.ScreenUpdating = True
    > End
    > End If
    >
    > ActiveCell.Offset(1, -11).Select ' Flyt celle ned. Fedtprocent celle er
    > valgt <------------ERROR !
    >
    > Next a
    >
    > Regards Shamran


    --

    Dave Peterson

  6. #6
    -[::::Shamran::::]-
    Guest

    Re: error: ActiveCell.Offset(0, -1).Select = Application-defined or object-defined error

    Just been looking at it agant ... what a mess .. I'll just have another
    look..don't be using any time on this..Let me cleare it up first ??


    regards, Shamran

    "-[::::Shamran::::]-" <[email protected]> wrote in message
    news:[email protected]...
    > Strange ... I don't think that I am going off the Sheet :
    >
    > The full code looks like this :
    >
    > Sub Fedtprocent()
    >
    > Sheets("data").Select
    > Range("O2").Select
    > ActiveCell.Offset(0, -11).Select 'Flytter aktivcelle til køn
    >
    > For a = 1 To 6000
    >
    > If ActiveCell = "F" Then 'Sortering for kvinder og 20-39 år
    >
    > ActiveCell.Offset(0, -1).Select ' Flyt activ celle til alder
    >
    > If ActiveCell >= 20 And ActiveCell >= 39 Then
    >
    > ActiveCell.Offset(0, 12).Select ' Flyt activ celle til fedtprocent
    >
    > If ActiveCell < 21 Then
    > myCount = Sheets("Fedtprocent").Range("C12") + 1
    > Sheets("Fedtprocent").Range("C12") = myCount
    > End If
    >
    > If ActiveCell >= 21 And ActiveCell < 33 Then
    > myCount = Sheets("Fedtprocent").Range("C13") + 1
    > Sheets("Fedtprocent").Range("C13") = myCount
    > End If
    >
    > If ActiveCell >= 33 And ActiveCell < 39 Then
    > myCount = Sheets("Fedtprocent").Range("C14") + 1
    > Sheets("Fedtprocent").Range("C14") = myCount
    > End If
    >
    > If ActiveCell >= 39 Then
    > myCount = Sheets("Fedtprocent").Range("C15") + 1
    > Sheets("Fedtprocent").Range("C15") = myCount
    > End If
    >
    > End If
    >
    > End If
    >
    >
    > If ActiveCell.Value = "" Then 'End macro ved tom celle
    > Sheets("Fedtprocent").Select
    > Range("L2").Select
    > Application.ScreenUpdating = True
    > End
    > End If
    >
    > ActiveCell.Offset(1, -11).Select ' Flyt celle ned. Fedtprocent celle er
    > valgt
    >
    > Next a
    >
    > End Sub
    >
    >
    >




  7. #7
    -[::::Shamran::::]-
    Guest

    Re: error: ActiveCell.Offset(0, -1).Select = Application-defined or object-defined error


    "Dave Peterson" <[email protected]> wrote in message
    news:[email protected]...
    > Excel has 256 columns.
    >
    > You're running a loop from 1 to 6000 that tries to move one column to the
    > left:
    > ActiveCell.Offset(0, -1).Select
    >
    > it should blow up pretty early in the loop.
    >


    Jep .. quiet stupid ... ille try harder next time ! *GGG*

    Thanks

    Shamran



  8. #8
    Dave Peterson
    Guest

    Re: error: ActiveCell.Offset(0, -1).Select = Application-defined orobject-defined error

    Maybe not...

    I didn't look at the rest of your code where you were changing selections.
    Maybe your loop takes care of that.

    (I didn't look close enough!)

    "-[::::Shamran::::]-" wrote:
    >
    > "Dave Peterson" <[email protected]> wrote in message
    > news:[email protected]...
    > > Excel has 256 columns.
    > >
    > > You're running a loop from 1 to 6000 that tries to move one column to the
    > > left:
    > > ActiveCell.Offset(0, -1).Select
    > >
    > > it should blow up pretty early in the loop.
    > >

    >
    > Jep .. quiet stupid ... ille try harder next time ! *GGG*
    >
    > Thanks
    >
    > Shamran


    --

    Dave Peterson

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1