+ Reply to Thread
Results 1 to 8 of 8

How to refer to entire a column in SUMIFs and VBA

  1. #1
    Registered User
    Join Date
    01-03-2020
    Location
    US
    MS-Off Ver
    2019
    Posts
    85

    Exclamation How to refer to entire a column in SUMIFs and VBA

    Hi, everyone
    I have a code for summarizing personnel work time while it's sensitive to 8 hours shift, means if the user types work time for a personnel in a specific date which their cumulative work time exceeds 8 hours, this code ignores it and just write 8 hours for that personnel in that date. This code was wrote by one of this forum's users, but I want to develop it to my real world problem in excel. In my own real world problem, I have large number of rows, maybe more than 10000 rows. In the last command, you see there is SumIfs object which refers to limited rows (rows 2 to 16). I want to develop it to entire rows in those determined columns. So, there is no need to make any change in the code every time I want to run the code (I update my excel table every week). I don't know how to make such a change in my code. I need to change all references such as R16C2 to the entire column so for large datasets, I don't need to make any change in my code). I'm new to VBA. Please help me to learn.
    And if it's possible, Please add some explanation between lines (green texts) so I can study the entire code.
    Attached Images Attached Images
    Attached Files Attached Files
    Last edited by fa2020; 05-25-2020 at 07:29 AM.

  2. #2
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2507 (Windows 11 Home 24H2 64-bit)
    Posts
    91,861

    Re: Revising A VBA Code

    Administrative Note:

    We would very much like to help you with your query, however the thread title does not really convey what your request is about. Tell us what you are trying to do, not how you think it should be done.

    Please take a moment to amend your thread title. Make sure that the title properly explains your request. Your title should be explicit and not be generic (this includes function names used without an indication of what you are trying to achieve).

    Please see Forum Rule #1 about proper thread titles and adjust accordingly. To edit the thread title, open the original post to edit and then click on Go Advanced (bottom right) to access the area where you can edit your title.

    (Note: this change is not optional. No help to be offered until this moderation request has been fulfilled.)
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help. It's a universal courtesy.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    NB:
    as a Moderator, I never accept friendship requests.
    Forum Rules (updated August 2023): please read them here.

  3. #3
    Registered User
    Join Date
    01-03-2020
    Location
    US
    MS-Off Ver
    2019
    Posts
    85

    Re: Revising A VBA Code

    Quote Originally Posted by AliGW View Post
    Administrative Note:

    We would very much like to help you with your query, however the thread title does not really convey what your request is about. Tell us what you are trying to do, not how you think it should be done.

    Please take a moment to amend your thread title. Make sure that the title properly explains your request. Your title should be explicit and not be generic (this includes function names used without an indication of what you are trying to achieve).

    Please see Forum Rule #1 about proper thread titles and adjust accordingly. To edit the thread title, open the original post to edit and then click on Go Advanced (bottom right) to access the area where you can edit your title.

    (Note: this change is not optional. No help to be offered until this moderation request has been fulfilled.)
    I revised my post. I think it's clear now.

  4. #4
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,875

    Re: How to refer to entire a column in SUMIFs and VBA

    Hi,

    I'd use rather ColumnLetterRowNumber than R1C1 notation and use the lr variable, which you already calculated, so instead of:

    Please Login or Register  to view this content.
    rather something like:

    Please Login or Register  to view this content.
    But of course you could use references to whole columns like

    Please Login or Register  to view this content.
    or if you want to stick to R1C1 notation:

    Please Login or Register  to view this content.
    But please do test if a number of such formulas do not slow down your file (you declare using Excel 2019, so it shall not be an issue, as excel recalculation engine is now quite effective in "skipping" unused cells - at least there are such rumours).
    Best Regards,

    Kaper

  5. #5
    Registered User
    Join Date
    01-03-2020
    Location
    US
    MS-Off Ver
    2019
    Posts
    85

    Re: How to refer to entire a column in SUMIFs and VBA

    Quote Originally Posted by Kaper View Post
    rather something like:

    Please Login or Register  to view this content.
    .
    Can you please explain " & LR & " meaning?

  6. #6
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,875

    Re: How to refer to entire a column in SUMIFs and VBA

    LR is a variable you used in the code. You have declared it as long (long integer) and assigned the number of the last non-empty row of the column A.
    It's even visible in a screenshot you've attached to post #1 :-) (declaration in line #2, value assigned in a line #9)


    and the "&" signs are used to concatenate constant parts of the formula with LR value (16 for data from attached file).

  7. #7
    Registered User
    Join Date
    01-03-2020
    Location
    US
    MS-Off Ver
    2019
    Posts
    85

    Re: How to refer to entire a column in SUMIFs and VBA

    Quote Originally Posted by Kaper View Post
    LR is a variable you used in the code. You have declared it as long (long integer) and assigned the number of the last non-empty row of the column A.
    It's even visible in a screenshot you've attached to post #1 :-) (declaration in line #2, value assigned in a line #9)
    I know, but why do we use the mark &??
    Why do we use two &s and some spaces between them?

  8. #8
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,875

    Re: How to refer to entire a column in SUMIFs and VBA

    see above, I've edited my post.

    PS. Please reply using just "reply", not "reply with Quote". It's obvious you are answering the post above. If you want to "focus" on something special - use selective quoting

+ 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] Need help revising Concatenate Formula
    By cjschulz in forum Excel Formulas & Functions
    Replies: 12
    Last Post: 12-28-2016, 03:20 PM
  2. revising a line of code
    By prdponce in forum Excel General
    Replies: 9
    Last Post: 12-08-2014, 03:56 PM
  3. [SOLVED] Need help on revising this if formula
    By thisring in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 03-29-2013, 07:40 PM
  4. Need help revising formulas
    By RicksMom in forum Excel General
    Replies: 2
    Last Post: 03-21-2011, 03:10 PM
  5. Macro for Export/Import - need help revising a code
    By emptycucumber in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-29-2009, 01:27 PM
  6. Combobox Revising with every access
    By sjumbo in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-15-2006, 01:30 PM
  7. need help revising
    By day in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-01-2006, 10:30 AM

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