Posts

Showing posts with the label vba

Run Time Error on Active formula in Excel Macro code

Run Time Error on Active formula in Excel Macro code I want to use the value of cell A5 of Sheet 2 to my active formula in macro in Sheet 1. However, I'm getting an Error 1004 (application defined or object defined error). If using a static value, for instance 100, instead of 'Sheet 2'!A5 , it is working. 'Sheet 2'!A5 Below is my code: ActiveCell.FormulaR1C1 = "=if('Sheet 2'!RC>'Sheet 2'!A5,""PASS"", ""FAIL"")" 1 Answer 1 You cannot mix-and-match xlA1 cell references with xlR1C1 cell references. A5 is R5C1 in xlR1C1 syntax. ActiveCell.FormulaR1C1 = "=if('Sheet 2'!RC>'Sheet 2'!R5C1,""PASS"", ""FAIL"")" Now in this formula, the RC is a relative row/relative column reference to the same cell on 'Sheet 2' that the active cell on the active ...

How can I loop through my “getElementById” VBA for multiple websites?

Image
How can I loop through my “getElementById” VBA for multiple websites? I'm part of a non-profit that sends letters to encourage hundreds of people in prison. They are often transferred unexpectedly, with no time to give notice of address change. However, each person's location while incarcerated is kept up-to-date and publicly accessible on the state government's website. I am trying to write VBA that goes through my "contact" list and visits each state government's prisoner location website (based on each prisoner's ID), then extracts each person's location from the website, places that in a column ($C) for that purpose which corresponds to the row for that specific person's name & ID. That way I could run a check automatically to confirm each one is still at the same location before I do an Excel mailmerge to print envelope labels with their addresses. Here's what I'm using to get the correct value (I've just been testing with a ...

Excel VBA editing comment if exists

Excel VBA editing comment if exists My code is checking if cell value from 2 sheets are different, if no it continue check for next row, if different it copy from sheet2 to sheet1 the cell value where I need and add to Cell in sheet1(where the value copied too) a comment with the old value. every time when the value changed again it remove the comment and put new one. I need to do a comment check if exist and append the old value to comment. I want that the comment will contain all the old values that changed in the cell. this is my piece of code: If Not IsEmpty(datasheet.Cells(iData, j).Value) Then comm = user & vbNewLine & "Old Date:" & vbNewLine & ActiveCell.Value datasheet.Cells(iData, j).Copy Destination:=ActiveCell With ActiveCell ActiveCell.Interior.ColorIndex = 0 With ActiveCell.Borders ...

Excel VBA running a macro across 50 sheets

Excel VBA running a macro across 50 sheets In excel VBA, I am trying to run a simple autofilter across 50 sheets, however, it only runs it across one sheet. Can anyone help? The code is below: Sub Macro2() ' ' Macro2 Macro ' Dim wb As Workbook For Each wb In Application.Workbooks Range(Selection, Selection.End(xlToRight)).Select Selection.AutoFilter Selection.End(xlToLeft).Select Range("G1").Select ActiveSheet.Range("$A$1:$AC$91").AutoFilter Field:=7, Criteria1:=Array("11" _ , "21", "22", "23", "31-33", "42", "44-45", "48-49", "51", "52", "53", "54", "55", "56", "61" _ , "62", "71", "72", "81"), Operator:=xlFilterValues Selection.End(xlToLeft).Select Next wb End Sub You can just paste your code...

Breakpoint Line Numbers in VB Editor

Image
Breakpoint Line Numbers in VB Editor Does anyone know how to get line numbers of breakpoints in the VB Editor programmatically? I can't find a way to do this currently with the VBA Extensibility Library (Microsoft Visual Basic for Applications Extensibility 5.3). FYI, I've already numbered my lines (starting with 10 and increasing by 10 for each line, excluding Dim 's) Dim Can you confirm you're talking about "Visual Basic for Applications" - (e.g. the VBA editor in Microsoft Office?), if so, which host-application are you using? – Dai Jun 30 at 19:47 Yes, Visual Basic for Applications (VBA). I'm using Excel 2016. I'd like to pull the line numbers where programmer has put breakpoints (not Stop statements in the code, but specifically breakpoints signaled by the red circles) ...

Open an Excel document from MS Word Using VBA

Open an Excel document from MS Word Using VBA I want to open a Excel sheet through Word VBA, paste information from the Word document row wise and save it. I have code for picking up specific information from the Word document but do not know how to open Excel and save it. I have found a solution in the following site: http://www.exceltip.com/st/Control_Excel_from_Word_using_VBA_in_Microsoft_Excel/463.html It is giving an error and also I do not know how to add a reference to the Excel library in Word. Error: Dim xlApp As Excel.Application - Compile Error "User defined type not defined" 1 Answer 1 You could do one of two things here -- 1) Change "Excel.Application" and "Excel.Workbook" to "Object" (late bound) or 2) In the VBA Editor, go to Tools > References and look for "Microsoft Excel x.0 Object Library" and check the checkbox. (early bound) ...

Saving attachments from a non Default Mailbox (Outlook 2010)

Saving attachments from a non Default Mailbox (Outlook 2010) I am trying to save attachments in a file called lifting reports. It works in my default inbox however I am trying to get it to work from a secondary inbox. The part of the code I have attempted to change is Set Inbox = ns.GetDefaultFolder(olFolderInbox) However I still cant get it to work correct.Can anyone assist? I am also trying to save the files on the date there were received not the date I am saving them. Any ideas? Sub SaveLiftingreports() 'Arg 1 = Folder name of folder inside your Inbox 'Arg 2 = File extension, "" is every file 'Arg 3 = Save folder, "C:UsersRontest" or "" ' If you use "" it will create a date/time stamped folder for you in your "Documents" folder ' Note: If you use this "C:UsersRontest" the folder must exist. SaveEmailAttachmentsToFoldernondefault "Lifting Reports", "xls", "" Sa...

Excel - Turn off the window that asks you to change links to a workbook

Excel - Turn off the window that asks you to change links to a workbook I generated links to some 100 workbooks but not all of them exist. This is fine because if they do not exist it usually means I don't need it. The links are generated based on string concatenation, and the final step is to paste by value to a cell. A sample of the link may look like this "='P:TEMP[wb1.xlsx]sheet1'!$D$1 "='P:TEMP[wb1.xlsx]sheet1'!$D$1 What I need now, is to remove the first quotation mark to bring the link "alive". I wrote a macro that does the find and replace in the row Sub BringAlive() Rows("18").Select Selection.Replace What:="""", Replacement:="", LookAt:=xlPart, _ SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _ ReplaceFormat:=False End Sub The only issue with this is that when a workbook doesn't exist, a window pops out asking me to find the workbook. I need to hit ESC many many times until the ...