+ Reply to Thread
Results 1 to 8 of 8

Coding Explanation Help Request

  1. #1
    Forum Contributor
    Join Date
    08-10-2009
    Location
    nottingham
    MS-Off Ver
    Excel 2010
    Posts
    110

    Coding Explanation Help Request

    Hi,

    I was hoping someone would take pity on me and help explain what's going on in some code I've been reviewing - i literally have no idea

    The coding is from an application that uses a form to add a new set of data to a table. I've been teaching myself VBA so have been breaking down and building my own from scratch and some of its got me baffled.

    Once the user has entered the data and clicked the submit button, it runs a Sub which calls three other Subs: WriteToTable, ExpandTable & SortTable.

    WriteToTable I've got (just) as it just adds the entered data to the next available blank row. I've not looked too hard at SortTable, but that appears to be just picking a column and sorting the data based on that criteria. What I don't get is the commands in ExpandTable.

    The Code is:

    Please Login or Register  to view this content.
    What on earth is going on here???

    I can't find a description i can understand of RefersToR1C1 anywhere so haven't got the foggiest about what this line is doing

    The Table its expanding is currently A1:D1 when no data is held. When data is added it fills row 2; so I'm assuming Its somehow telling it to add the new row to the Table and "expand" it so its now held as A1:D2?

    If someone could put what's happening into plain English for me it would be appreciated.

    Thanks

  2. #2
    Forum Expert
    Join Date
    10-09-2012
    Location
    Dallas, Texas
    MS-Off Ver
    MO 2010 & 2013
    Posts
    3,049

    Re: Coding Explanation Help Request

    You can always check the microsoft help.

    https://msdn.microsoft.com/en-us/lib...erstor1c1.aspx

    http://www.datawright.com.au/excel_r..._names_vba.htm


    RefersTo is pasrt of defining a named range (and apparently a table) where the R1C1 is a particular way of doing so. Instead of "a1" you use r1c1 as "r1c1" (row 1, column 1).
    http://www.excel-easy.com/vba/examples/formulaR1C1.html
    Last edited by mikeTRON; 03-09-2015 at 02:56 PM.
    Please ensure you mark your thread as Solved once it is. Click here to see how.
    If a post helps, please don't forget to add to our reputation by clicking the star icon in the bottom left-hand corner of a post.

  3. #3
    Forum Contributor
    Join Date
    08-10-2009
    Location
    nottingham
    MS-Off Ver
    Excel 2010
    Posts
    110

    Re: Coding Explanation Help Request

    Hi Mike

    Thanks for the reply and the links. I now know the R & C relate to Row and Column

    What i Don't get is why it's being used twice?

    Ignoring the last line for a second, which appears to just be sorting the data in the table based on the values in Column B, why is the other line referred to twice?

    Please Login or Register  to view this content.
    I don't understand what is happening in the first line and what the change from "("A1")" to "("Table").CurrentRegion.Address)" is doing.

    I'm clearly naive because as far as I'm concerned, the activeWorkbook is just defining which workbook is being referred to; the .Names is referring to the Names already in that workbook; & the Add method(?) is adding to something already defined which in this case is the Name "Table".

    After that I'm stuck - Any ideas?

  4. #4
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: Coding Explanation Help Request

    It is a pretty weird way of writing it, but essentially you add a defined name pointing to A1, then immediately resize it to include the whole region around A1. It would be simpler to size it once only.

    I'm surprised the second one works since you are supposed to be passing an R1C1 style address but the default for Address is A1 style. It would be simpler to use:

    Please Login or Register  to view this content.
    Remember what the dormouse said
    Feed your head

  5. #5
    Forum Contributor
    Join Date
    08-10-2009
    Location
    nottingham
    MS-Off Ver
    Excel 2010
    Posts
    110

    Re: Coding Explanation Help Request

    Quote Originally Posted by romperstomper View Post
    It is a pretty weird way of writing it, but essentially you add a defined name pointing to A1, then immediately resize it to include the whole region around A1.
    really? the workbook already has a Named Object called table, so if that code is adding one of the same name; what happened / is happening to the original one? is it automatically replaced / deleted?

    Also...

    How does currentRegion work? Am i right in assuming the region is defined as the selected range and continuously spreads out as long as an adjacent cell has a value within in?

    Thanks again Mike for your help on this one.

  6. #6
    Forum Expert
    Join Date
    10-09-2012
    Location
    Dallas, Texas
    MS-Off Ver
    MO 2010 & 2013
    Posts
    3,049

    Re: Coding Explanation Help Request

    Google and the Microsoft help answers all of this stuff very well.
    https://msdn.microsoft.com/en-us/lib.../ff196678.aspx

    CurrentRegion: property is useful for many operations that automatically expand the selection to include the entire current region, such as the AutoFormat method.
    This property cannot be used on a protected worksheet.


    Also, if you are interested in learning more about VBA, you should buy the Excel Power Programming with VBA book, I found it easy to digest AND very useful at learning the fundamentals like this. This allows your googleFu to be much more accurate.

  7. #7
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: Coding Explanation Help Request

    It gets replaced. CurrentRegion expands in each direction until it is bounded by empty cells.

  8. #8
    Forum Contributor
    Join Date
    08-10-2009
    Location
    nottingham
    MS-Off Ver
    Excel 2010
    Posts
    110

    Re: Coding Explanation Help Request

    Thanks guys for the advice.

    I'm currently reading Excl Programming for Dummies by John Walkenbach but not that far into it. It all makes sense once explained but i don't know enough of the rules surrounding the functions and methods yet so can get confusing at times.

    so to summarize my original question:

    The first line was creating a object named "Table" and set to range A1

    The second line was re-creating it and re-sizing it straight away to that cell's current Reigion.

    If that's it then this thread is sorted.

    Thanks again.
    Last edited by inq80; 03-09-2015 at 06:01 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Request for syntax explanation.
    By Jim15 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 07-17-2013, 04:53 PM
  2. Reminder request - "write vba coding on buttons to active attached user form"
    By virgome in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-19-2013, 05:14 AM
  3. MS Outlook - VBA Coding Request for Monitoring Ftp Servers
    By ganeshinscribe in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-05-2012, 10:03 AM
  4. MS Outlook - VBA Coding Request for Monitoring Ftp Servers
    By ganeshinscribe in forum Outlook Programming / VBA / Macros
    Replies: 0
    Last Post: 07-05-2012, 05:57 AM
  5. Coding help request (I think?)
    By adodson in forum Excel General
    Replies: 7
    Last Post: 11-23-2005, 08:50 PM

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