+ Reply to Thread
Results 1 to 6 of 6

Value in textbox in userform to check with a dynamic range in module macro

  1. #1
    Registered User
    Join Date
    05-22-2014
    Posts
    37

    Value in textbox in userform to check with a dynamic range in module macro

    Hi.

    This is a part of a big macro (in a module).
    Here is the structure of my macro (in module);
    I get a RaNge using LastRow; range("A" & LastRow) where LastRow is range("D" & Rows.Count).End(xlUp).Row.
    I then launch the userform; userform.Show
    In the userform, there is a TextBoX. The input in this TextBoX is a VariaBle.
    What I want is to check if this VariaBle is in the RaNge. If it is, then use the VariaBle. IF NOT, then I would like to get a message box that tells me "Try again", and send me back to the userform.

    Til now I have tried to do this by doing like this:

    Public VariaBle as string (as this can contain both numbers and text, typ. 134A)
    In the macro in the module I have as said earlier gotten the RaNge from LastRow.
    userform.Show
    In the userform I have in the commandbutton: VariaBle=userform.TextBoX
    then, back in the module I have:
    For Each cell in RaNge
    if application.proper(VariaBle)=application.proper(cell) then
    sMR=cell.row
    end if
    next cell
    I then discovered that the value of sMR is 0(zero) if the VariaBle is not found in the RaNge, so I wrote strait after the line over;
    if sMR=0 then
    msgbox "Can't find what you want"
    call macro (this is the same macro as I am writing in now)
    end if

    And then there are lots of codes and calculations.

    This method does actually all it sholud (I get all the results I want, even those at the end of the macro), BUT when the macro is done, I get an error (1004, application-defined or object-defined error)????

    I hope someone understand what I'm trying to say, and can help me.
    By the way, how do I make those nice excel lines into this post?

    Thanks!!
    Last edited by flabb; 01-15-2016 at 05:57 AM.

  2. #2
    Valued Forum Contributor Gatti's Avatar
    Join Date
    06-08-2015
    Location
    Brasil, São Paulo, Ribeirão Preto
    MS-Off Ver
    365
    Posts
    346

    Re: Value in textbox in userform to check with a dynamic range in module macro

    Hello.

    Welcome to Forum

    Please, put your codes inside the CODE Tags

    This way:

    Please Login or Register  to view this content.
    I will check now your problem... 1 sec

    If possible, make a sample using your problem and post the workbook here

  3. #3
    Registered User
    Join Date
    05-22-2014
    Posts
    37

    Re: Value in textbox in userform to check with a dynamic range in module macro

    I'm obvious an idiot...I can't fint the tag area (when replying)...
    This is work related, so I don't dare to post the workbook here..

  4. #4
    Valued Forum Contributor Gatti's Avatar
    Join Date
    06-08-2015
    Location
    Brasil, São Paulo, Ribeirão Preto
    MS-Off Ver
    365
    Posts
    346

    Re: Value in textbox in userform to check with a dynamic range in module macro

    Thats why I said a "sample"

    You just create a sample workbook with different data, but same code and problems

    By the way, when writting the msg, just check the "#" button, it is the Code Tag

  5. #5
    Registered User
    Join Date
    05-22-2014
    Posts
    37

    Re: Value in textbox in userform to check with a dynamic range in module macro

    In Module:

    Please Login or Register  to view this content.
    In userform:
    Please Login or Register  to view this content.
    Hope this helps!
    Last edited by flabb; 01-14-2016 at 09:47 AM.

  6. #6
    Registered User
    Join Date
    05-22-2014
    Posts
    37

    Re: Value in textbox in userform to check with a dynamic range in module macro

    I solved it by public dim and new code in userform;
    module:
    Please Login or Register  to view this content.
    userform:
    Please Login or Register  to view this content.
    The only thing I miss now, is to make the formMastnummer (inputbox) active (setfocus) if TesT=2 (as you can see in the codes), but this does not work...

+ 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. Transfer data from userform to macro in a module, and textbox input as numbers?
    By flabb in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-13-2016, 02:25 PM
  2. [SOLVED] Trying to refer to a textbox in a userform from a module in a for next loop
    By forrestgump1980 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-16-2015, 03:24 PM
  3. [SOLVED] Userform & Dynamic Controls & Class Module
    By sarndt01 in forum Excel Programming / VBA / Macros
    Replies: 21
    Last Post: 09-18-2014, 01:53 PM
  4. Replies: 0
    Last Post: 03-08-2014, 08:02 AM
  5. Blank Check for Userform textbox
    By anandvh in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 11-06-2012, 11:35 AM
  6. Userform Error Check and Textbox Help
    By Impartial Derivative in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 12-06-2011, 10:20 AM
  7. Pass values from UserForm ListBox/ TextBox to run the codes of a Module
    By SunOffice in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 09-05-2011, 08:59 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