+ Reply to Thread
Results 1 to 3 of 3

VBA - Enter value, count value, enter count, clear first value, repeat until end of data.

  1. #1
    Forum Contributor
    Join Date
    11-17-2018
    Location
    Los Angeles
    MS-Off Ver
    Office 2010
    Posts
    208

    VBA - Enter value, count value, enter count, clear first value, repeat until end of data.

    I have looked at/watch many tutorials and samples but none address my particular dilemma.

    I need VBA code that when I push a button would do the following:
    1. Enter value “X” in column S, cell (S1)
    2. Count values (how many “YES”, or whatever is there) in a range (BA59:CO59)
    3. Input count in column EA, cell EA1, corresponding to the row for S1,
    4. Clear first value entered in S1
    5. Repeat on next column cell (S2) until the end of the column (S29). Place “X” in S2, etc.


    In other words:
    1. STEP ONE. In column S, cell S1, enter “X”.
    2. STEP TWO. Then, in another part of the sheet (range BA59:CO59), count how many times “YES” is found in that range (in this particular example, the range is made of nine cells). As of now, there are 4 “YES” in this range. I can be anything aside from “YES” too.
    3. STEP THREE. Then input that value (4) into cell EA1, which corresponds to the same row as where the “X” was entered in cell S1.
    4. STEP FOUR. Clear the “X” from S1, in column S.
    5. STEP FIVE. Enter “X” on S2 of column S and repeat the process… until end of column data (S29). Then the code should stop. Of course, pressing the button again will repeat the whole process each time.


    NOTE (just for reference): in step two, the range of nine cells where the “YES” are found is a dynamic range in my actual workbook. The “YES” count will change dynamically according to which row will have the “X” in column S. In other words, each time the “X” is moved to another row in column S, that will automatically trigger a new calculation (formulas are in place to do so in my actual worksheet) which will give a different “YES” count.

    In the attached file, the dynamic calculation from where the “YES” count is derived is not included because I was not able to successfully copy that area into this sample file (the formulas in place require a lot of manual adjustment since they are using INDIRECT and VBA code and such to link to other sheets.

    In other words, the VBA code in this sample file will output a 4 count for each row in column S (unless the “YES” cells are manually modified). But it should automatically find the right count once I use it in the actual workbook.

    Also, I do have data in between columns S and EA and I do have other VBA code in place. I am hoping that the VBA solution provided will be a module or sheet code that will not interfere with other modules or subs. The attached file has no VBA.

    Thanks and I truly appreciate the help given.

  2. #2
    Valued Forum Contributor
    Join Date
    09-30-2018
    Location
    Vlaams Brabant Belgium
    MS-Off Ver
    365
    Posts
    456

    Re: VBA - Enter value, count value, enter count, clear first value, repeat until end of da

    this should do it


    Please Login or Register  to view this content.
    Please be as complete as possible in your asking so it may save use all the time to rework the solution because you didn't give all the requirements. If you have a layout in mind please work it out first so we can adapt our solution to it. Thanks.
    If you have been helped, maybe you could click the *

  3. #3
    Forum Contributor
    Join Date
    11-17-2018
    Location
    Los Angeles
    MS-Off Ver
    Office 2010
    Posts
    208

    VBA - Enter value, count range, enter count, clear first value, repeat until end of data

    Yes it did!!!

    Brilliant!!! Amazing!!!

    I changed the code you provided to use COUNTIF instead of COUNTA because with COUNTA it was only counting if the range had text (the "YES") and it was also counting blank cells when there was no text in them. In reality, in that range I have an IF formula and the COUNTA didn't work with that. That's my fault. I didn't think of that. Sorry.

    Also I added a line of code to FIRST start by clearing the destination range (EA). After running the code I realized that (in the actual workbook) there were left overs from the prior run (in my actual workbook, sometimes the range goes to 23 or 50 or 100, etc).

    Thank you so much.

    NOTE: I will mark "SOLVED" on this post after a few days because for some reason my posts magically "vanish" when I mark them solved on the same day.

    I include here the code with the trivial changes I made and the working file for future reference.


    Please Login or Register  to view this content.
    Last edited by Luisftv; 10-23-2021 at 08:53 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. Replies: 1
    Last Post: 10-22-2019, 02:16 AM
  2. [SOLVED] VBA Count Emails in outlook mail box and enter count and oldest email date into excel cell
    By fireguy7 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 05-24-2018, 11:04 AM
  3. [SOLVED] If cell meets date requirement enter 1, if not enter 0, if blank don't enter anything.
    By billrogers184 in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 05-11-2017, 02:04 PM
  4. [SOLVED] Count only data within a line break (alt-enter) with specific criteria in adjacent column
    By jparve3283 in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 06-20-2016, 10:44 AM
  5. How to count text entered with ALT+ENTER using a count function
    By bethy1234 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 05-29-2015, 02:41 PM
  6. Macro - enter data in next clear row after every run
    By maryam_husn in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-27-2014, 08:39 AM
  7. VBA to count dates and enter data based on settings
    By anfdrew in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-15-2013, 12:25 AM

Tags for this Thread

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