VBA WEEKDAY Function (Syntax + Example) - Excel Champs

文章推薦指數: 80 %
投票人數:10人

The VBA WEEKDAY function is listed under the date category of VBA functions. When you use it in a VBA code, it returns the day number (ranging from 1 to 7) ... SkiptocontentHome➜VBATutorial➜TopVBAFunctions➜VBAWEEKDAYFunction(Syntax+Example)TheVBAWEEKDAYfunctionislistedunderthedatecategoryofVBAfunctions.WhenyouuseitinaVBAcode,itreturnsthedaynumber(rangingfrom1to7)byusingthenumberofthedayfromthesupplieddate.Insimplewords,itreturnsthenumberofthedaywithintheweek.TableofContentCloseSyntaxArgumentsExampleNotesRelatedFunctionsSyntaxWeekday(Date,[FirstDayOfWeek])ArgumentsDate:Avaliddateforwhichyouwanttogettheweekday.[FirstDayOfWeek]:Astringtodefinethefirstdayoftheweek[ThisisanoptionalargumentandifomittedVBAtakesvbSundaybydefault].vbUseSystemDayOfWeek–Asperthesystemsettings.vbSunday–SundayvbMonday–MondayvbTuesday–TuesdayvbWednesday–WednesdayvbThursday–ThursdayvbFriday–FridayExampleTopracticallyunderstandhowtouseVBAWEEKDAYfunction,youneedtogothroughthebelowexamplewherewehavewrittenavbacodebyusingit:Subexample_WEEKDAY() Range("B1").Value=Weekday(Range("A1")) EndSubIntheabovecode,wehaveusedWEEKDAYtogettheweekdayfor(Wednesday,May15,2019)thedatewhichwehaveinthecellA1andintheresult,wehave4inthecellB1.ThedayisWednesday,whichisthefourthdayoftheweek(ithastakenSundaythefirstdayoftheweek),sothatithasreturned4intheresult.NotesIfthedatespecifiedisavalueotherthanadateorastringthatcan’tberecognizedasadate,VBAwillreturntherun-time13error.RelatedFunctionsDATE|DATEADD|DATEDIFF|DATEPART|DATESERIAL|DATEVALUE|DAY|MONTH|MONTHNAME|WEEKDAYNAME|YEAR



請為這篇文章評分?