Skip to main content

Posts

Showing posts with the label Vlookup

Excel VBA autofill date range

How to auto fill a range of cells with date? To auto fill range of cells can be done via VBA or manually. To manually fill a range of cells with date. Type two dates on two cells and highlight the two cells and manually drag to the desired range of cells. Drag from the bottom right with the "+" sign on it. See screen shot below:            To do it via VBA is quite simple also using autofill function. Sub AutoFill_Dates()   Dim srcRange As Range   Dim destRange As Range   Set srcRange = ActiveSheet.Range("E1") 'E1 should have valid date value   Set destRange = ActiveSheet.Range("E1:E15") 'E1 to E15 will be filled with the dates (starting the date specified on E1)   srcRange.AutoFill destRange, xlFillSeries 'xlFillSeries will auto fill the dates in sequence End Sub Cheers.. Hope it helps..

Excel 2010 date difference

How to use datedif function in Excel? How to find date difference between two dates in Excel? How to find date difference by month, year or days in Excel? Excel has a built-in function and does the heavy lifting to date difference between two dates. Excel uses the “datedif” function to easily compute the date difference  by days, months or years. Notice the Datedif function has a single “f” at the end it’s not DateDiff. If you accidentally type double “f” at the end of the function excel will return an error and will just display “#NAME?” which basically means that the function is not recognized by Excel. Here’s the function: =DATEDIF(A1,C1,"d")  ==== > this function find the date difference by days for the values of A1 and C1 =DATEDIF(A3,C3,"m")  ==== > this function find the date difference by months for the values of A3 and C3 =DATEDIF(A5,C5,"y")  ==== > this function find the date difference by yea...

Combine excel cell values

How to combine excel values from different cells? Combining values in excel saves time of course, unless you like to buy some time to drag the work and keep yourself busy. But how to combine values using excel formula? If you have data of first name and last name in different cells and you want to combine those values in another cell without re-typing the data. This formula below will come handy. Let’s assume this value: A1 – contains first name B1 – contains last name D1 – will contain the combine cell values in first name and last name format D2 – will contain the combine cell values in last name, comma and first name format. For cell D1 the formula is: =A1&" "&B1 (Notice the space in between the “&” (ampersand sign) if it is a double space the combine value will have a double space) For cell D2 the formula is: =B1&", "&A1 (Notice that the cell address has been reverse and the comma after cell B1....

Word VBA delete page selection

Sub Macro_VBA_Delete_Page() Selection.GoTo wdGoToPage, wdGoToAbsolute, 2 Selection.Bookmarks("\Page").Select Selection.Delete Unit:=wdCharacter, Count:=1 End Sub Selection.GoTo wdGoToPage, wdGoToAbsolute, 2 Line above will goto page number "2" Selection.Bookmarks("\Page").Select This will select the whole page. Selection.Delete Unit:=wdCharacter, Count:=1 As the keyword specified "Delete", it will delete the whole page   To delete 2 subsequent pages using VBA use code below: Sub Del_pages() Dim i  For i = 1 To 2 Selection.GoTo wdGoToPage, wdGoToAbsolute, 2 Selection.Bookmarks("\Page").Select   Selection.Delete Unit:=wdCharacter, Count:=1  Next End Sub Code above will delete page 2 and page 3 on the word document Selection.GoTo wdGoToPage, wdGoToAbsolute, 2 Code above will goto page 2 and once page 2 is deleted, page 3...

Delete page in word document

To delete a selected page anywhere in a word document, is quite easy and straight forward. Follow steps below: 1. Press Ctrl+G on the keyboard 2. Find and Replace window will open. (see image) 3. The default tab will be “Go To tab".    Type "\page" (don't include the quotes), on "Enter page number" box. 4. Click "Go To" button, it will select the whole page. 5. Click the "Close" button. Find and replace window will close. 6. Finally, press "Delete" key on the keyboard to delete the selected page. 7. Press Ctrl+Z, if you change your mind it will bring back the deleted page. Tested in Word 2010. Cheers!! Hope it helps.. ========================= Heaven's Dew Fall https://play.google.com/store/apps/details?id=soulrefresh.beautiful.prayer Android Catholic Rosary App - Guide https://play.google.com/store/apps/details?id=com.myrosaryapp&hl=en-GB Educationa...

Delete word Hyperlinks via VBA

This simple VBA code will delete all the hyperlinks on the active document. Reading a word document with hyperlinks, is quite annoying sometimes. If the hyperlink is accidentally click then it will open a browser and disrupt the momentum of reading the document. And worse if the document link, points to a malicious website then it will be another issue. Use the VBA code below to delete all hyperlinks on a word document. The code will also display the number of lines on the document and also the total number of hyperlinks on the document. =============================== Sub HyperLines()  Dim nLines, i, x  Selection.WholeStory  i = Selection.Hyperlinks.Count  nLines = Selection.Range.ComputeStatistics(Statistic:=wdStatisticLines)  MsgBox "Number of Lines:" & nLines & " Number of Hyperlinks:" & i  For x = 1 To nLines  Selection.GoTo What:=wdGoToLine, Which:=wdGoToAbsolute, Count:=x  On Error Resume Next  Appli...

Disable Replace Text in Word using VBA

In word while you are typing, Word is smart enough to replace typing errors. But if you are not typing in English language, it will be a mess if word will automatically replace the word. Solution is to disable the feature "Replace Text as you type." This simple VBA code snippet will disable the options "Replace Text as you type". Disable is set to "False". Application.AutoCorrect.ReplaceText = False It can be done manually by clicking on: (Word 2010 procedure) 1. File 2. Options 3. Proofing 4. Auto Correct Options 5. AutoCorrect Tab 6. Untick "Replace text as you type" 7. Click "OK" 2 times to exit But the one liner VBA code is quite simple rather than clicking so many times. To enable via VBA just set the value to True.

Word VBA macro get username

A Word VBA macro to get username and record the date and time the document was opened and closed. Private Sub Document_Open() -- Will run the macro if the document is open Private Sub Document_Close() -- Will run the macro if the document is close To run the macro, create a text file on this location. D:\DocMonitor\wordUserClose.txt D:\DocMonitor\wordUserOpen.txt Change the file name and the location to any path and any desired file name. ============================== Private Sub Document_Open() Dim xUserName As String Dim xDate As String xUserName = Application.UserName Dim xfileSystem, xwriteStream xDate = Now() Set xfileSystem = CreateObject("Scripting.FileSystemObject") 'fs.CreateTextFile "D:\DocMonitor\wordUserOpen.txt" Set xwriteStream = xfileSystem.OpenTextFile("D:\DocMonitor\wordUserOpen.txt", 8, 0) xwriteStream.WriteLine vbCrLf xwriteStream.WriteLine Open Date and Time xwriteStream.WriteLine xDate xwriteStream.WriteLine ...

Unable to print word 2010 document

Assuming the printer is setup properly, and able to print from PDF, notepad or other software and also able to print from printer driver test page. But when printing a specific word document in Word 2010, it will just show "Not responding" the document will hang and will not print. There is no restriction set on the document but cannot print. Try steps below: Click on the "File" tab, click on the "Review" menu. From the "Review" tab, select "tracking" change the option from: "Final: Show Markup" to "Final". Check image below: Save the document or save it to a different file name. And try printing again, if everything goes right the document will be able to print. Paper tray settings will also cause a problem with printing the document. Documents from another party that retain printer settings on the document will not print if the printer of the other party does not have...

How to select objects behind text in word

Objects that are set as "Behind Text", cannot receive focus or cannot be selected when clicking the object. If the  image, picture or  other objects cannot be selected. Then the object is set to display "behind text". To select the picture, image or other objects. Follow steps below: In Word ribbon, go to "Home" tab. Select "editing", and click on "Select objects". Then click on the object that is set as "behind text", then the object should be selected. See screen shot below: Hope it helps.. It will come handy, when you're in hurry.

Excel find workbook path or location

To check excel workbook path or location via vba, the code below will get the path or location of the workbook. Application.ActiveWorkbook.Path     ===  Path only without the workbook name Application.ActiveWorkbook.FullName === Display path and the workbook name Sample code: Sub Display_WB_Location() Dim xPath_Workbook xPath_Workbook = Application.ActiveWorkbook.FullName 'xPath_Workbook = Application.ActiveWorkbook.Path Msgbox xPath_Workbook End Sub If the file is open, just click on "File" then click "Info" to show workbook location. See image below: Sometimes it's useful to know the location, especially if you're working on a lot of folders and files. And forget which folder or the file location. Cheers!!! Hope it helps!!!

Excel VBA get data from Word Table

How to get Word table value or data from Excel using VBA? Sharing or getting data from word table to Excel via VBA. Below is a piece of VBA code that will do the task to get a value from Word using Excel VBA. This example assumes that there is a single table in Microsoft Word. And the table is 3x8, 3 columns and 8 rows per column. So just for reference, for those who are trying to wrap up on what is row and column. Please check the image below, Value1, Value2 and Value3 represent columns. (3 columns on this example) And each Value column has 8 lines, which is basically called rows. (8 rows on this example) VBA code below will get the data from a word file and display the value using an msgbox command in Excel VBA. It will also place the value to the Excel Worksheet where the VBA is being executed. Code below assumes that there is a worksheet called "Sheet1". If a worksheet named "Sheet1" is not found on the wo...