Results 1 to 11 of 11

Thread: Excel Ranges

  1. #1

    Thread Starter
    Member
    Join Date
    Jun 2005
    Posts
    41

    Excel Ranges

    Alright, I have a range that I want the user to be able to change. Really, its an index of cells which my program references.

    Right now I have:
    VB Code:
    1. Sheets("Master").Select
    2.   MaxCount = Application.CountA(Range("A50", "A500"))
    3.   Range("B50").Select
    4.   Set IndexRng = Range(ActiveCell, ActiveCell.Offset(MaxCount - 1, MaxCount - 1))
    And later:
    VB Code:
    1. CurVal = CurVal + Application.Index([Master!IndexRng], Cur(i), Cur(i - 1))
    When I changed the range from "B50:AL88" to IndexRng in the statement directly above, I get the error "Type Mismatch (Error 13)", and I'm not sure whats wrong.
    Thanks in advance.

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

    Re: Excel Ranges

    Could be either two things. One your data in the range contains an invalid data type for your formatted range. A letter in an
    numeric field, etc. Or your parameters for .Index are mismatched?

    If you move the range back it still works, correct?
    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
    Member
    Join Date
    Jun 2005
    Posts
    41

    Re: Excel Ranges

    Rob,
    Yes, if I change Master!IndexRng to Master!B50:AL86, the code works.

    Does the range variable store the *actual* contents of the cells, or does it just store the equivalent of B50:AL86? The latter is what I want.

    Also, I posted a problem in a thread a few below this, to reset my code before or after each use. Do you have any insights on that?

    Thanks!
    Last edited by Bartender; Jul 11th, 2005 at 08:53 AM.

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

    Re: Excel Ranges

    The Range object represents a selection of cells so its probably safe to assume that it represents the data and not just the
    string begin/end designators.
    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

  5. #5

    Thread Starter
    Member
    Join Date
    Jun 2005
    Posts
    41

    Re: Excel Ranges

    Rob,
    How can I make it so that the index function:
    VB Code:
    1. Application.Index([Master!IndexRng], Cur(i), Cur(i - 1))
    has a value in indexrng that I don't need to set, but rather that self selects. That's all I'm trying to do here. I don't want to 'hard code' in the size of the index, as in saying "B2:AL89", but rather I want to make it so that the index range is flexible and self counting. I tried to do that in the code in my original post, but I guess I failed. How should I have coded it? I'm quite inexperienced with programming.
    Also, I'm not 100% sure that my "Set IndexRng..." is working right, so my problem could be there as well.
    Thanks for your time.
    Last edited by Bartender; Jul 11th, 2005 at 08:53 AM.

  6. #6

    Thread Starter
    Member
    Join Date
    Jun 2005
    Posts
    41

    Re: Excel Ranges

    Alright, I'm still interested in the answer, but I am trying to move on so....
    I have set the range to "B50:GS200" in order to allow plenty of room for expansion of the index from its current size, and it doesn't seem to run any slower than when I had it set to "B50:AL86" mainly, I think, because it still only calls to the first 38 references in the index.
    Is there anything wrong with this? Am I shooting myself in the foot when this goes to 300,000 iterations rather than just the 5000 that I tested it at?

    Thanks for your help.

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

    Re: Excel Ranges

    If your index is only needing to beidentified as a used range then no need to specify the large range and loop. You could place it on
    its own sheet and use the Cells.SpecialCells(xlCellTypeLastCell).Row to find the last cell with no looping.
    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

  8. #8

    Thread Starter
    Member
    Join Date
    Jun 2005
    Posts
    41

    Re: Excel Ranges

    Sorry Rob,
    I was misleading with what I said. The loop is not identifying the index, the loop is the program, and the program iterates through this loop between 720 to 320,000 times depending on user input. This loop itself actually references a value in the index between 5 and 9 times each time the loop is called, so the index is really being used up to 2 and a half million times or so per run of the program. This is why I was concerned if hard coding the actual index size to be much bigger than what I needed would slow me down.
    So my index is really a 37x37 block, but I've made it so the program thinks the index is a 160x160 block or so, so users can expand the index... and I was hoping this wouldn't affect the running time of the program, since the inputs are still only calling the first 37x37 block of the index.

    I would try to do what you suggested, but I have had absolutely NO luck with getting a
    VB Code:
    1. Application.Index([Master!IndexRng], Cur(i), Cur(i - 1))
    function to work with anything but a static range that I pre-select, ie "B50:AL87" in place of IndexRng.
    [Master!IndexRng], Master!IndexRng, IndexRng, [IndexRng],[Master!ActiveCell:ActiveCell.Offset(variable,variable)], etc..... all haven't worked.
    Thanks again for your time!

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

    Re: Excel Ranges

    I was going to try some demo code but Application.Index doesnt show as taking any arguments? I'm on my first cup of
    coffee so what am I missing?
    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

  10. #10

    Thread Starter
    Member
    Join Date
    Jun 2005
    Posts
    41

    Re: Excel Ranges

    Rob,
    Jeez, I have no idea. I know it doesnt seem to take any arguments, its never done the fancy formatting for me. But try creating a, say, 8x8 block of numbers in excel, and then use Application.Index([Sheet1!"A1:H8"],2,4) and see if it doesn't give you the value at 2 rows 4 columns.

    Maybe my computer is just humoring me?
    Good luck, and thanks!

  11. #11

    Thread Starter
    Member
    Join Date
    Jun 2005
    Posts
    41

    Re: Excel Ranges

    I noticed that I typed:
    Application.Index([Sheet1!"A1:H8"],2,4)
    in my post above, where I believe that should have been:
    Application.Index([Sheet1!A1:H8],2,4)
    Sorry

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