Results 1 to 8 of 8

Thread: [RESOLVED] Selection Range in Excel as object variable

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2009
    Posts
    4

    Resolved [RESOLVED] Selection Range in Excel as object variable

    I want to select a range of cells of about 1 to 10 rows and 5 to 50 columns from one workbook and based on that selection will set the values in a different workbook. Here is my code that I cannot make work.

    Code:
    Public Sub DataTransferTwo()
        Dim MyRange As Range
        Dim Pname As String
        Dim Loc As String
        Dim Clt As String
        Dim MyDate As Date
        '
     Workbooks("Master Project Status.xls").Worksheets "Proposals").Activate
            Set MyRange = Selection.Value        (This is far as I get then errors-Object Required or Wrong Method/Property)
            With MyRange
            MyDate = MyRange("", Range("B1").End(xlDown).Value)
            Pname = MyRange("", Range("D1").End(xlDown).Value)
            Clt = MyRange("", Range("E1").End(xlDown).Value)
            Loc = MyRange("", Range("G1").End(xlDown).Value)
           End With
        '
        Workbooks("Proposal Tracking.xlsx").Worksheets("ACT").Activate
        Range("B4000").End(xlUp).Offset(1, 0).Select
        Selection = Pname
        Range("D4000").End(xlUp).Offset(1, 0).Select
        Selection = Clt
        Range("E4000").End(xlUp).Offset(1, 0).Select
        Selection = Loc
        Range("G4000").End(xlUp).Offset(1, 0).Select
        Selection = MyDate
    
    End Sub
    Any help would be greatly appreciated
    Last edited by RobDog888; Jul 20th, 2009 at 12:26 PM. Reason: Not Sure where this should be posted to what forum

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Selection Range in Excel as object variable

    Thread Moved

    Welcome to the Forums
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3

    Thread Starter
    New Member
    Join Date
    Jul 2009
    Posts
    4

    Re: Selection Range in Excel as object variable

    Where should I have posted this???

  4. #4
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Selection Range in Excel as object variable

    Set MyRange = Selection.Value (This is far as I get then errors-Object Required or Wrong Method/Property)
    you are trying to assign a value to a range object
    try
    set myrange = selection.range

    Where should I have posted this???
    here
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  5. #5
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Selection Range in Excel as object variable

    In case you haven't noticed the breadcrumb links above the posts (and below them), "here" is the Office Development forum.

    You had posted in the VB6 forum, but the "VB Editor" in Office programs is actually VBA rather than VB, so the VB6 forum is not really apt (they have some similarities, but lots of differences too).

  6. #6

    Thread Starter
    New Member
    Join Date
    Jul 2009
    Posts
    4

    Re: Selection Range in Excel as object variable

    Wesconn1...

    Well ....it didn't quite correct the problem.

    Code:
    Public Sub DataTransferTwo()
        Dim Pname As ( I changed this from String to Range to Variant to Long and nothing mattered)
        Dim Loc As Variant
        Dim Clt As Variant
        Dim MyDate As Date
        Dim MyRange As Variant
        Set MyRange = Selection (This time I got a property error when I included .Range to Selction so I just removed it and it went by only to create another error below)
            '
    With MyRange
        Pname = MyRange("", Range("D1").End(xlDown).Value) ( Now I get Error 13 Typematch)
        Clt = MyRange("", Range("E1").End(xlDown).Value)
        Loc = MyRange("", Range("G1").End(xlDown).Value)
        MyDate = MyRange("", Range("B1").End(xlDown).Value)
    End With
    '
     '
        Workbooks("Proposal Tracking.xlsx").Worksheets("ACT").Activate
        Range("B4000").End(xlUp).Offset(1, 0).Select
        Selection = Pname
        Range("D4000").End(xlUp).Offset(1, 0).Select
        Selection = Clt
        Range("E4000").End(xlUp).Offset(1, 0).Select
        Selection = Loc
        Range("G4000").End(xlUp).Offset(1, 0).Select
        Selection = MyDate
    End Sub
    I aapreciate any help you can give
    thanks VBA666
    Last edited by RobDog888; Jul 20th, 2009 at 12:26 PM.

  7. #7
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Selection Range in Excel as object variable

    as you give no indication as what part is not working now, hard to make suggestions

    do you get error, incorrect result or nothing happen?
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  8. #8

    Thread Starter
    New Member
    Join Date
    Jul 2009
    Posts
    4

    Re: Selection Range in Excel as object variable

    Quote Originally Posted by westconn1 View Post
    as you give no indication as what part is not working now, hard to make suggestions

    do you get error, incorrect result or nothing happen?
    I appolgize for not updating this status issue it was resolved after I sent this.

Posting Permissions

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



Click Here to Expand Forum to Full Width