+ Reply to Thread
Results 1 to 6 of 6

VBA to select a defined range

  1. #1
    Shawn
    Guest

    VBA to select a defined range

    Thanks in advance to all who help on this site.

    I have the below code:


    Public Sub MMR()

    ' Keyboard Shortcut: Ctrl+x

    Dim DataSD As Worksheet
    Dim MMR As Range
    Set MMR = DataSD.Range("MMRrange")

    MMR.Select

    End Sub

    When I Set MMR to = DataSD.Range("MMRrange") the MMRrange refers to a
    defined range of cells on the DataSD worksheet. However, I have something
    wrong for when I run this program this line gives an error?




    --
    Thanks
    Shawn

  2. #2
    Don Guillett
    Guest

    Re: VBA to select a defined range

    Try this without anything else to goto a range/cell named bill
    However, it is rarely necessary to select to do something. More info?

    Sub gothere()
    Application.Goto "bill"
    End Sub


    --
    Don Guillett
    SalesAid Software
    [email protected]
    "Shawn" <[email protected]> wrote in message
    news:[email protected]...
    > Thanks in advance to all who help on this site.
    >
    > I have the below code:
    >
    >
    > Public Sub MMR()
    >
    > ' Keyboard Shortcut: Ctrl+x
    >
    > Dim DataSD As Worksheet
    > Dim MMR As Range
    > Set MMR = DataSD.Range("MMRrange")
    >
    > MMR.Select
    >
    > End Sub
    >
    > When I Set MMR to = DataSD.Range("MMRrange") the MMRrange refers to a
    > defined range of cells on the DataSD worksheet. However, I have something
    > wrong for when I run this program this line gives an error?
    >
    >
    >
    >
    > --
    > Thanks
    > Shawn




  3. #3
    George Nicholson
    Guest

    Re: VBA to select a defined range

    In your code you have declared DataSD as a Worksheet but you haven't set it
    to anything before you use it. This causes an error.

    Set DataSD = Worksheets("SheetNameContainingMMRange") 'This line is
    missing
    Set MMR = DataSD.Range("MMRrange") 'Needs
    to know what DataSD is or you'll get an error

    HTH,
    --
    George Nicholson

    Remove 'Junk' from return address.


    "Shawn" <[email protected]> wrote in message
    news:[email protected]...
    > Thanks in advance to all who help on this site.
    >
    > I have the below code:
    >
    >
    > Public Sub MMR()
    >
    > ' Keyboard Shortcut: Ctrl+x
    >
    > Dim DataSD As Worksheet
    > Dim MMR As Range
    > Set MMR = DataSD.Range("MMRrange")
    >
    > MMR.Select
    >
    > End Sub
    >
    > When I Set MMR to = DataSD.Range("MMRrange") the MMRrange refers to a
    > defined range of cells on the DataSD worksheet. However, I have something
    > wrong for when I run this program this line gives an error?
    >
    >
    >
    >
    > --
    > Thanks
    > Shawn




  4. #4
    M. Authement
    Guest

    Re: VBA to select a defined range

    I think you need to Set the DataSD object.

    "Shawn" <[email protected]> wrote in message
    news:[email protected]...
    > Thanks in advance to all who help on this site.
    >
    > I have the below code:
    >
    >
    > Public Sub MMR()
    >
    > ' Keyboard Shortcut: Ctrl+x
    >
    > Dim DataSD As Worksheet
    > Dim MMR As Range
    > Set MMR = DataSD.Range("MMRrange")
    >
    > MMR.Select
    >
    > End Sub
    >
    > When I Set MMR to = DataSD.Range("MMRrange") the MMRrange refers to a
    > defined range of cells on the DataSD worksheet. However, I have something
    > wrong for when I run this program this line gives an error?
    >
    >
    >
    >
    > --
    > Thanks
    > Shawn




  5. #5
    Bob Phillips
    Guest

    Re: VBA to select a defined range

    Neither DataSD nor MMR have been set to any objects.

    In addition the syntax is

    Set DataSD = Worksheets("Sheet1")
    Set MMR = DataSD.Range("A1")

    or so

    --
    HTH

    Bob Phillips

    "Shawn" <[email protected]> wrote in message
    news:[email protected]...
    > Thanks in advance to all who help on this site.
    >
    > I have the below code:
    >
    >
    > Public Sub MMR()
    >
    > ' Keyboard Shortcut: Ctrl+x
    >
    > Dim DataSD As Worksheet
    > Dim MMR As Range
    > Set MMR = DataSD.Range("MMRrange")
    >
    > MMR.Select
    >
    > End Sub
    >
    > When I Set MMR to = DataSD.Range("MMRrange") the MMRrange refers to a
    > defined range of cells on the DataSD worksheet. However, I have something
    > wrong for when I run this program this line gives an error?
    >
    >
    >
    >
    > --
    > Thanks
    > Shawn




  6. #6
    Shawn
    Guest

    RE: VBA to select a defined range

    This link also helped me:

    http://groups-beta.google.com/group/...9892a2449a7ced


    --
    Thanks
    Shawn


    "Shawn" wrote:

    > Thanks in advance to all who help on this site.
    >
    > I have the below code:
    >
    >
    > Public Sub MMR()
    >
    > ' Keyboard Shortcut: Ctrl+x
    >
    > Dim DataSD As Worksheet
    > Dim MMR As Range
    > Set MMR = DataSD.Range("MMRrange")
    >
    > MMR.Select
    >
    > End Sub
    >
    > When I Set MMR to = DataSD.Range("MMRrange") the MMRrange refers to a
    > defined range of cells on the DataSD worksheet. However, I have something
    > wrong for when I run this program this line gives an error?
    >
    >
    >
    >
    > --
    > Thanks
    > Shawn


+ 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