+ Reply to Thread
Results 1 to 10 of 10

Find date in horizontal table and add values below in one cell

  1. #1
    Registered User
    Join Date
    08-19-2012
    Location
    Germany
    MS-Off Ver
    Excel 2010
    Posts
    50

    Find date in horizontal table and add values below in one cell

    Greetings!
    What I want to accomplish is that the macro finds the current date in a horizontal table with multiple rows of dates, and then add one number below and below that 3 other numbers as %-numbers in that style: xx/yy/zz (30/40/30 for example). The point is it should not add the digits after the commata, but take the full number without %-symbol (37,53% =38). You can find my code here, its commented to make it easy to understand. By helping me you would make me very happy because I'm not getting it on my own or with google like my other macros.


    Please Login or Register  to view this content.
    Ive tried it and it doesnt even find the current date and selects the cell :/

    Yours sincerely,
    Taktiker from Germany, who feels drunken from doing Excel macros without really having any knowledge about VBA
    Last edited by Taktiker; 08-19-2012 at 04:50 PM.

  2. #2
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: Find date in horizontal table and add values below in one cell

    hi Taktiker, welcome to Excelforum, try this slightly changed option of your code:

    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    08-19-2012
    Location
    Germany
    MS-Off Ver
    Excel 2010
    Posts
    50

    Re: Find date in horizontal table and add values below in one cell

    Hello,
    1. Can you explain me, what the , , (<--- the space) xlFormulas and xlwhole after Date do?
    2. I tried the macro on my table, but it didnt find the date, though the date is in the range and is set as a date. When I did an extra sheet with just the date somewhere, it did find it. I send you the link to my workbook and an image with the relevant data without macros. Could you look why my table does not want to cooperate with the macro? I have to say that there are a lot of texts and merged cells within the searchrange, but I when I unmerged them it still didnt find it.

    Thank you already for the first reply!

    Edit: I added a .xlx data for the excel 2003 users
    Last edited by Taktiker; 08-19-2012 at 04:44 PM.

  4. #4
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: Find date in horizontal table and add values below in one cell

    The code could not work due to the wrong range set. Please check attchment, run code "Tagebucheintrag"

    1. VB help file extract Find Method

    Finds specific information in a range, and returns a Range object that represents the first cell where that information is found. Returns Nothing if no match is found. Doesn’t affect the selection or the active cell.

    For information about using the Find worksheet function in Visual Basic, see Using Worksheet Functions in Visual Basic.

    expression.Find(What, After, LookIn, LookAt, SearchOrder, SearchDirection, MatchCase, MatchByte, SearchFormat)

    expression Required. An expression that returns a Range object.

    What Required Variant The data to search for. Can be a string or any Microsoft Excel data type.

    After Optional Variant. The cell after which you want the search to begin. This corresponds to the position of the active cell when a search is done from the user interface. Note that After must be a single cell in the range. Remember that the search begins after this cell; the specified cell isn’t searched until the method wraps back around to this cell. If you don’t specify this argument, the search starts after the cell in the upper-left corner of the range.

    LookIn Optional Variant. The type of information.

    LookAt Optional Variant. Can be one of the following XlLookAt constants: xlWhole or xlPart.

    SearchOrder Optional Variant. Can be one of the following XlSearchOrder constants: xlByRows or xlByColumns.

    SearchDirection Optional XlSearchDirection. The search direction.

    XlSearchDirection can be one of these XlSearchDirection constants.
    xlNext default
    xlPrevious

    MatchCase Optional Variant. True to make the search case sensitive. The default value is False.

    MatchByte Optional Variant. Used only if you’ve selected or installed double-byte language support. True to have double-byte characters match only double-byte characters. False to have double-byte characters match their single-byte equivalents.

    SearchFormat Optional Variant. The search format.

    Remarks
    The settings for LookIn, LookAt, SearchOrder, and MatchByte are saved each time you use this method. If you don’t specify values for these arguments the next time you call the method, the saved values are used. Setting these arguments changes the settings in the Find dialog box, and changing the settings in the Find dialog box changes the saved values that are used if you omit the arguments. To avoid problems, set these arguments explicitly each time you use this method.

    2. With the defined range in the sample file code it would never find it.
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    08-19-2012
    Location
    Germany
    MS-Off Ver
    Excel 2010
    Posts
    50

    Re: Find date in horizontal table and add values below in one cell

    Please Login or Register  to view this content.
    If I use this macro, it does nothing. Neither a runtime error or the error message that the macro should produce, nor filling in the numbers below the date. Do you have an idea, why? (the original macro does not either, this is just simplified to be more handy).

    EDIT: Out of some ridiculous reason, the cells were formatted with text color white, so I didnt see it, when it filled anything in. By randomly clicking on it and seeing the data in the formular part, I realized the problem and could fix it. At the moment its filling in. But now I have another problem: The percent numbers (today 38%, 38%, 24%) are combined to 0/0/0. Any idea why?
    Last edited by Taktiker; 08-19-2012 at 04:25 PM.

  6. #6
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: Find date in horizontal table and add values below in one cell

    The posted workbook in post #4 works as expected.

    The posted code in #5 misses End sub.

    How do you run a code?

  7. #7
    Registered User
    Join Date
    08-19-2012
    Location
    Germany
    MS-Off Ver
    Excel 2010
    Posts
    50

    Re: Find date in horizontal table and add values below in one cell

    hey Ive updated my last post. check it.

  8. #8
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: Find date in horizontal table and add values below in one cell

    Quote Originally Posted by Taktiker View Post
    now I have another problem: The percent numbers (today 38%, 38%, 24%) are combined to 0/0/0. Any idea why?
    It's logical if you take values from empty cells: Cells(37,6) - F37 - it is empty. Plus all you variables: Prot, Carb, Fat reference same cell - F37 and it is empty.

  9. #9
    Registered User
    Join Date
    08-19-2012
    Location
    Germany
    MS-Off Ver
    Excel 2010
    Posts
    50

    Re: Find date in horizontal table and add values below in one cell

    Uhm, the original document contained correct info in the linked cells. But I have fixed the issue. The numbers were %-digits, so 38% was 0,38 and the integer variable made 0 out of it. By using double variables and multiplying them by 100 I got the right numbers. Thank you very much for your help, if I could I would give you 100x reputation
    Final Code:
    Please Login or Register  to view this content.

  10. #10
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: Find date in horizontal table and add values below in one cell

    if we are done, please mark the thread as Solved, see Forum Rules for details

+ 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