+ Reply to Thread
Results 1 to 16 of 16

Counting Cells into a new worksheet

  1. #1
    Registered User
    Join Date
    04-27-2013
    Location
    Los Angeles
    MS-Off Ver
    Excel 2007, Excel 2010
    Posts
    7

    Counting Cells into a new worksheet

    Hello all,

    I'm having trouble finding the right VBA code/s to work this one. I have a data, where in the column it just reads 1, 8, and 10, and I need to count all 1's, 8's, and 10's in sequence within the column and paste it in a new worksheet. I would do everything manually using the COUNT or even COUNTIF functions, but I do have a lot of data just in that one column. Is there any VBA code I can use to make the data arrangement automatic?

    I'm uploading a test excel file.

    For example, I would count this:
    1
    1
    1
    1
    1
    1
    8
    8
    8
    8
    10

    this is equal to 11 because it's the number of all 1's, 8's, and 10's.
    Attached Files Attached Files

  2. #2
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: Counting Cells into a new worksheet

    Hi, hellonikki,

    maybe just reference the whole column
    Please Login or Register  to view this content.
    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  3. #3
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,770

    Re: Counting Cells into a new worksheet

    Try this...

    Please Login or Register  to view this content.
    Refer the attached file for details
    Attached Files Attached Files


    If your problem is solved, then please mark the thread as SOLVED>>Above your first post>>Thread Tools>>
    Mark your thread as Solved


    If the suggestion helps you, then Click *below to Add Reputation

  4. #4
    Forum Contributor
    Join Date
    07-04-2012
    Location
    Al Khor, Qatar
    MS-Off Ver
    Excel 2013
    Posts
    101

    Re: Counting Cells into a new worksheet

    Hi,

    Try this code i used your sample workbook for this codes,

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    04-27-2013
    Location
    Los Angeles
    MS-Off Ver
    Excel 2007, Excel 2010
    Posts
    7

    Re: Counting Cells into a new worksheet

    Thank you guys so much for all your help! I'm in the process of learning how to code, and you guys truly have helped tremendously!

    to tangangtanga:

    Your code seems to fit what I need. I do have another question: The real data that I have have counts on two columns. How would the code be modified such that it counts 2 columns and it provides output in two columns as well? I tried just putting the same code again, but changing the range (instead of "A", I put "B"). Is that right?

  6. #6
    Forum Contributor
    Join Date
    07-04-2012
    Location
    Al Khor, Qatar
    MS-Off Ver
    Excel 2013
    Posts
    101

    Re: Counting Cells into a new worksheet

    Yeah! you can just change all the A's to B's in that code leaving only this line
    Please Login or Register  to view this content.
    as it is. post again if something goes wrong and post your sample workbook also so I can modify it directly.

  7. #7
    Registered User
    Join Date
    04-27-2013
    Location
    Los Angeles
    MS-Off Ver
    Excel 2007, Excel 2010
    Posts
    7

    Re: Counting Cells into a new worksheet

    to tangangtanga:

    I tried doing what you said, but somehow in the output tab, for the second column, the values are offsetted (?) after the last value in the first column. I'm uploading part of the data that I'm truly working on. I apologize if I messed up your coding! >_<
    Attached Files Attached Files

  8. #8
    Forum Contributor
    Join Date
    07-04-2012
    Location
    Al Khor, Qatar
    MS-Off Ver
    Excel 2013
    Posts
    101

    Re: Counting Cells into a new worksheet

    Please Login or Register  to view this content.
    You did pretty good how long have you been learning VBA?

  9. #9
    Forum Contributor
    Join Date
    07-04-2012
    Location
    Al Khor, Qatar
    MS-Off Ver
    Excel 2013
    Posts
    101

    Re: Counting Cells into a new worksheet

    Sorry the site went crazy and it just doubled my post.
    Last edited by tangangtanga; 04-27-2013 at 11:24 PM. Reason: Double post

  10. #10
    Registered User
    Join Date
    04-27-2013
    Location
    Los Angeles
    MS-Off Ver
    Excel 2007, Excel 2010
    Posts
    7

    Re: Counting Cells into a new worksheet

    Ah! I didn't think of putting another counter, haha. Thank you so much for your help!

    I learned VBA quite a long time ago during my first year in college. I never thought I'd need it two years later, so I got rusty, haha. I need to relearn everything again.

    Once again, thank you for your help!

  11. #11
    Forum Contributor
    Join Date
    07-04-2012
    Location
    Al Khor, Qatar
    MS-Off Ver
    Excel 2013
    Posts
    101

    Re: Counting Cells into a new worksheet

    np just add up my rep lol. Thank you.

  12. #12
    Registered User
    Join Date
    04-27-2013
    Location
    Los Angeles
    MS-Off Ver
    Excel 2007, Excel 2010
    Posts
    7

    Re: Counting Cells into a new worksheet

    Just did lol. I didn't know about reps, haha.

  13. #13
    Registered User
    Join Date
    04-27-2013
    Location
    Los Angeles
    MS-Off Ver
    Excel 2007, Excel 2010
    Posts
    7

    Re: Counting Cells into a new worksheet

    to tangangtanga (or to anyone else who can answer this question):

    Would you mind if I ask another question? I was debating whether to post an entirely new thread or continue on here since I marked this thread as "solved", but I figured I'll just continue on here because it is the same data/problem.

    I'm trying a different approach in organizing my data, and this time, I would rather just count all the 1's, 8's, and 10's and put it in different columns in a different worksheet, at the same time, at the end of the last cell the number 10, it looks up the timestamp across the row and posts it in the very first column, The uploaded excel file will show what I want to happen this time.

    Would this be doable? How drastic would the changes in the coding be?

    I tried doing the vlookup within vba for the original data (the data above this post/s) that I'm working on, and it didn't work for me, here's the code:

    Please Login or Register  to view this content.
    I apologize if it seems like a stretch, but I'd appreciate it so much if anyone would help me in organizing this data.
    Attached Files Attached Files

  14. #14
    Forum Contributor
    Join Date
    07-04-2012
    Location
    Al Khor, Qatar
    MS-Off Ver
    Excel 2013
    Posts
    101

    Re: Counting Cells into a new worksheet

    HelloNikki,

    Sorry for the late response coz i'm currently in the office lol. here is the code
    Please Login or Register  to view this content.
    Just post it again if you need some modifications and don't forget the rep button lol.

  15. #15
    Registered User
    Join Date
    04-27-2013
    Location
    Los Angeles
    MS-Off Ver
    Excel 2007, Excel 2010
    Posts
    7

    Re: Counting Cells into a new worksheet

    to tangangtanga:

    Hey I really appreciate your help!

    I tried running the code, but I keep on getting a "subscript out of range" error. The code seems fine though, I can follow it actually. I wonder where the issue could be?

    EDIT: oh I figured it out! I just inserted this code:

    Please Login or Register  to view this content.
    that was missing lol. Thanks a lot tangangtanga!
    Last edited by hellonikki; 04-28-2013 at 07:34 PM. Reason: post correction/update

  16. #16
    Forum Contributor
    Join Date
    07-04-2012
    Location
    Al Khor, Qatar
    MS-Off Ver
    Excel 2013
    Posts
    101

    Re: Counting Cells into a new worksheet

    np.. lol where's my rep?

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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