+ Reply to Thread
Results 1 to 8 of 8

Vba Modification to Incorporate an Input Box

  1. #1
    Valued Forum Contributor
    Join Date
    09-09-2009
    Location
    Liverpool, England
    MS-Off Ver
    W: 2021 H: 365
    Posts
    940

    Vba Modification to Incorporate an Input Box

    Morning all,

    I use the following code to validate some dates in my data but I'm going to be handing the process over shortly so I'd like to modify the code to make it easier for my successor. The code applies a conditional format to the column called "Invoice Date" based on the month number I manually change each month (Selection.FormatConditions.Add Type:=xlExpression, Formula1:="=MONTH(" + InvDate + ")=6"). What I would prefer is an input box that only allows you to input a number between 1 and 12 and then incorporates that as part of the conditional format.

    Please Login or Register  to view this content.
    If you have any queries just give me a shout.

    Thanks in advance,

    Snook
    Last edited by The_Snook; 07-12-2016 at 09:53 AM.

  2. #2
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: Vba Modification to Incorporate an Input Box

    A slight rewrite of your code, to avoid doing all that selecting:

    Edit: I should have mentioned that the rewrite includes your requirement for an inputbox to choose a month number!!

    Please Login or Register  to view this content.
    Last edited by Olly; 07-12-2016 at 05:15 AM.
    let Source = #table({"Question","Thread", "User"},{{"Answered","Mark Solved", "Add Reputation"}}) in Source

    If I give you Power Query (Get & Transform Data) code, and you don't know what to do with it, then CLICK HERE

    Walking the tightrope between genius and eejit...

  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: Vba Modification to Incorporate an Input Box

    Where the inputbox value should be stored (In which variable) ?


    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 Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Vba Modification to Incorporate an Input Box

    Hi,

    You'll need to Dim an additional month number variable.

    Also note that rarely is is necessary to use .Select. This adds a time overhead since VBA needs to first jump back to Excel and then jump back to VBA which with some code, e.g. loops can seriously slow things down. So avoid .Select and the similar .Activate wherever possible. Just work directly with the object.

    Also note it's good programming practice to have some system of identifying what the variables are. For instance I generally preface String variable names with "st", Long variable names with "l", Boolean variable names with "b", ...etc. with relatively short code this may not seem a big deal but with longer code and more variables it helps when debugging code and examining the value of variables. I've not modified your variables but the Month Numebr variable for the Input box is a Long variable hence lMonthNo. Note there's a school of thought that using the Integer variable is not needed since VBA automatically converts Integers to Long 'behind the scenes', and hence you can avoid that step by always using Long variables rather than Integer.

    So try

    Please Login or Register  to view this content.
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  5. #5
    Valued Forum Contributor
    Join Date
    09-09-2009
    Location
    Liverpool, England
    MS-Off Ver
    W: 2021 H: 365
    Posts
    940

    Re: Vba Modification to Incorporate an Input Box

    Thanks all. Is it possible to build in an error message if the value input isn't valid?

    Snook

  6. #6
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: Vba Modification to Incorporate an Input Box

    Quote Originally Posted by The_Snook View Post
    Thanks all. Is it possible to build in an error message if the value input isn't valid?
    Sure - see the additional rows highlighted in red:

    Please Login or Register  to view this content.

  7. #7
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Vba Modification to Incorporate an Input Box

    Hi,

    One way, immediately after the End With instruction add the following two lines

    Please Login or Register  to view this content.

  8. #8
    Valued Forum Contributor
    Join Date
    09-09-2009
    Location
    Liverpool, England
    MS-Off Ver
    W: 2021 H: 365
    Posts
    940

    Re: Vba Modification to Incorporate an Input Box

    Absolutely poifect!

    Cheers Olly and Richard, much appreciated.

+ 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. How to incorporate a progress bar
    By biznez in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-07-2015, 02:06 PM
  2. Incorporate SQL Query into Macro
    By lynnexcel in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-08-2015, 12:54 PM
  3. IF Statements that incorporate addition
    By Spenserk in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 09-03-2014, 04:00 PM
  4. [SOLVED] VBA to incorporate a hyperlink to another tab
    By jake14569 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 02-22-2013, 11:43 PM
  5. how to incorporate an excel add in into a sub
    By luv2glyd in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-01-2011, 12:47 PM
  6. How do i incorporate a progress bar.....
    By JonesZoid in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 06-11-2008, 05:49 PM
  7. Best way to Incorporate 3 Variables?
    By Furnasjm in forum Excel General
    Replies: 3
    Last Post: 04-14-2007, 02:39 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