+ Reply to Thread
Results 1 to 14 of 14

Storing numbers through inpubox

  1. #1
    Registered User
    Join Date
    05-08-2016
    Location
    France
    MS-Off Ver
    2013
    Posts
    58

    Storing numbers through inpubox

    Hi everybody!!

    I have a problem with this code :
    Please Login or Register  to view this content.
    I try to keep the column number corresponding to the "year" enter by the user through an inputbox. For example if I put 2016 and that this year is in the header (1, 4) so I'll store the number 4 in the variable "chx" in order to user it after. But each time it reply "year not found" while it's wrong!
    If somebody has an idea about the problem!?
    thank you very much!

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

    Re: Storing numbers through inpubox

    Attach a sample workbook. Make sure there is just enough data to make it clear what is needed. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate. Make sure your desired results are demonstrated, mock them up manually if needed. Remember to desensitize the data.

    Click on GO ADVANCED and use the paperclip icon to open the upload window.

    View Pic


    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

  3. #3
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,523

    Re: Storing numbers through inpubox

    Try this
    Please Login or Register  to view this content.
    Last edited by jindon; 05-13-2016 at 01:22 AM. Reason: Misunderstanding Fixed for "If .Cells(1, ii).Value = Val(response) Then"

  4. #4
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,819

    Re: Storing numbers through inpubox

    The loop you have posted looks like a basic linear search algorithm. I might use Excel's MATCH() function to find the year, with appropriate error trapping if the year is not found.

    How to access worksheet functions in VBA: https://msdn.microsoft.com/en-us/lib...ice.14%29.aspx
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

  5. #5
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,907

    Re: Storing numbers through inpubox

    I'd use Application.Match instead of Worksheetfunction.Match because

    1. On using Application code doesn't go into debug when error.
    2. Error trapping is much easier when using Application.

    For more information read following link http://www.snb-vba.eu/VBA_Arrays_en.html#L_6.16
    It's about using worksheetfunctions in Arrays but principle is the same.

  6. #6
    Registered User
    Join Date
    05-08-2016
    Location
    France
    MS-Off Ver
    2013
    Posts
    58

    Re: Storing numbers through inpubox

    Thank you for your answer!

    @jindon when x is defined like that can I use this variable in an other sub? Because when I use the msgbox to check it I find the good number then "0" in the other?

  7. #7
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,523

    Re: Storing numbers through inpubox

    Not sure how you want to use it though.

    Example
    Please Login or Register  to view this content.

  8. #8
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,819

    Re: Storing numbers through inpubox

    when x is defined like that can I use this variable in an other sub?
    It depends on how you use x, but, as jindon coded it, x is dimmed only for "procedure level" scope, so it is only defined while that procedure is running and only available to that procedure.

    Here's one discussion on scope. http://www.cpearson.com/Excel/Scope.aspx It is a common concept in computer science, so there should be many other tutorials and discussions out there.

  9. #9
    Registered User
    Join Date
    05-08-2016
    Location
    France
    MS-Off Ver
    2013
    Posts
    58

    Re: Storing numbers through inpubox

    Hi! everybody!!

    @jindon Thank you very much that works now!! Do you now if there is a simple way for .evaluate() can find "2016" in "Word_2016"? It's not really important but in case you know...
    @MrShorty Thank you this link is very interesting and those precisions!

  10. #10
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,523

    Re: Storing numbers through inpubox

    You mean like this?
    Please Login or Register  to view this content.

  11. #11
    Registered User
    Join Date
    05-08-2016
    Location
    France
    MS-Off Ver
    2013
    Posts
    58

    Re: Storing numbers through inpubox

    Can you quickly explain me what is between both blanks?

  12. #12
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,523

    Re: Storing numbers through inpubox

    What is
    Quote Originally Posted by marron1
    between both blanks?
    ?

  13. #13
    Registered User
    Join Date
    05-08-2016
    Location
    France
    MS-Off Ver
    2013
    Posts
    58

    Re: Storing numbers through inpubox

    Quote Originally Posted by jindon View Post
    What is
    Quote Originally Posted by marron1
    between both blanks?
    ?
    ?
    Sorry for my english! I meant "brackets"!

  14. #14
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,523

    Re: Storing numbers through inpubox

    OK, the reason I used Evaluate method is that you might have multiple 2016 and want to know each column.
    Evaluate method can list all of them, if needed.

    Before, it looks up the value 2016, but now it looks up "Word_2016" that means length of response from the right end.
    Right(A1,Len(response)) should return "2016", if A1 contains "Word_2016".

    HTH

+ 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. Storing numbers through inpubox
    By maroon1 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-13-2016, 12:00 AM
  2. Storing Numbers
    By Gerson496 in forum Excel General
    Replies: 15
    Last Post: 07-14-2015, 05:44 AM
  3. [SOLVED] Need Variable Details for Storing numbers with multiple decimal points
    By Karthik Sen in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-23-2014, 05:34 PM
  4. Replies: 3
    Last Post: 09-09-2014, 08:29 AM
  5. Storing the output generated from random numbers in different cells
    By rafat125 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 04-12-2013, 02:07 AM
  6. Storing numbers
    By duringtheeventof in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-05-2011, 02:26 AM
  7. Storing a Value
    By Josh_123456 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-08-2005, 06:26 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