Posts

Showing posts with the label excel-vba

VBA Webscrape not picking up elmenents; pick up frames/tables?

Image
VBA Webscrape not picking up elmenents; pick up frames/tables? Tried asking this question. Didn't get many answers. Can't install things onto my work computer. https://stackoverflow.com/questions/29805065/vba-webscrape-not-picking-up-elements Want to scrape a morningstar page into Excel with the code below. Problem is, it doesn't feed any real elements/data back. I actually just want the Dividend and cap gain distribution table really from that link I put into my_Page. This is usually easiest way, but an entire page scrape way, AND Excel-->Data-->From Web DON'T work. I've tried to use get elements by tag name and class before, but I failed at being able to do it in this case.This might be the way to go... Once again, just want that Dividend and Cap Gain distribution table. Not seeing any results in via the Debug.print Working code below, just need to parse into excel. Updated attempt below: Sub Macro1() Dim IE As New InternetExplorer IE.Visible = True ...

Periodically Copying Concatenated Data in Excel To Second Sheet While Primary Sheet Remains Active for Data Entry

Periodically Copying Concatenated Data in Excel To Second Sheet While Primary Sheet Remains Active for Data Entry I am pulling data from various cells on Sheet1 in Excel and copying the values to specific cells on a row in Sheet2 every specified period of time. I almost have my project completed but am unable to copy concatenated data in the same manner. How would I incorporate the following excel statement into my code for the data to be copied on sheet2 from sheet1? The output should go into cell AB on Sheet2. Not to confuse the issue but the reason the code is done in this manner is so that data can be entered on sheet 1 which will be the active sheet on the screen at all times but data will be periodically be saved to sheet2. Excel Statement i need to incorporate and output to Cell "AB" on sheet2: =CONCATENATE(Sheet1!I9,", ",Sheet1!I10,", ",Sheet1!I11,", ",Sheet1!I12) Current Code: Option Explicit Public dTime As Date Sub ValueStore() Dim...

Excel VBA Macro: Scraping data from site table that spans multiple pages

Excel VBA Macro: Scraping data from site table that spans multiple pages Thanks in advance for the help. I'm running Windows 8.1, I have the latest IE / Chrome browsers, and the latest Excel. I'm trying to write an Excel Macro that pulls data from StackOverflow (https://stackoverflow.com/tags). Specifically, I'm trying to pull the date (that the macro is run), the tag names, the # of tags, and the brief description of what the tag is. I have it working for the first page of the table, but not for the rest (there are 1132 pages at the moment). Right now, it overwrites the data everytime I run the macro, and I'm not sure how to make it look for the next empty cell before running.. Lastly, I'm trying to make it run automatically once per week. I'd much appreciate any help here. Problems are: Code (so far) is below. Thanks! Enum READYSTATE READYSTATE_UNINITIALIZED = 0 READYSTATE_LOADING = 1 READYSTATE_LOADED = 2 READYSTATE_INTERACTIVE = 3 READYSTATE_COMPLETE = 4 ...

Locating cells in an external workbook and copying over information automatically

Locating cells in an external workbook and copying over information automatically I am new to VBA and am trying to create an automatic filing system. I want to copy invoice information directly over from an invoice 'InvoiceMaker' workbook to a separate 'InvoiceTracker' workbook each time an invoice has been filled out. I have a long line of free invoice numbers in the 'Tracker' workbook and i want to assign specific information from each new invoice to each free invoice number. I have been writing to code to automatically search for the invoice number using 'find' in the column B where these free invoice numbers are located. Once this has been found the information in specific cells can be copied over directly to this row of cells. I have come across a problem with finding the location of the invoice numbers in the external workbook. The error message 91 keeps recurring 'Object Variable or With block variable not set', even though a name has been...

How to create an addin installer excel

How to create an addin installer excel I have a addin file named as VitaE.xlam . I want to make an addin installer of this file for my client. I have everything added, changed the ribbon using customUI, added all the macros etc. The final step is what I am not able to find anywhere. I just need to create a VitaE.exe file for installing all the addins that are created in VitaE.xlam . VitaE.xlam VitaE.exe VitaE.xlam By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Automate Filter Selection in Pivot table of Excel using macro

Automate Filter Selection in Pivot table of Excel using macro How can I jump to the first selection of a date filter in Excel? The filter is connceted to a cube and everyday new date gets refreshed and added to the filter automatically. I want to unselect the current selection and select the next date. And I want to build a MACRO for this task. Please suggest how to do it. This is Off-Topic, please don't ask how to do x without offering what you tried so far. If you want a tutorial on how to build a Macro for something like this please use google. Quote from stackoverflow.com/help/on-topic: Questions asking us to recommend or find a book, tool, software library, tutorial or other off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it. Please take a look at How to Ask. – Paxz Jun 29 at 11:00 ...

VB.NET check range of cells in excel whether data length is less then 7, add “wwww” to the left until it becomes 7 characters

VB.NET check range of cells in excel whether data length is less then 7, add “wwww” to the left until it becomes 7 characters i was wondering if is there any vb.net function that loop through excel file and check for the data length under a specific column? i've got a column where the data shouldn't be less than 7 characters any help would be appreciated :) Please show what you have tried so far: No attempt was made. – Pᴇʜ Jun 29 at 11:07 1 Answer 1 There are countless examples of getting excel data, so this answer is just for the padding. You can use String.PadLeft using the overload that supplies length and the character to pad with. String.PadLeft Dim yourString = "test" yourString = yourString.PadLeft(7,"w") ...

Add regular expression reference before running the macro vba

Add regular expression reference before running the macro vba code : Public Sub CallDeleteAllText(control As IRibbonControl) Call LeaveNumbers End Sub Public Function PullOnly(strSrc As String, CharType As String) Dim RE As RegExp Dim regexpPattern As String Set RE = New RegExp CharType = LCase(CharType) Select Case CharType Case Is = "digits": regexpPattern = "D" Case Is = "letters": regexpPattern = "d" Case Else: regexpPattern = "" End Select RE.Pattern = regexpPattern RE.Global = True PullOnly = RE.Replace(strSrc, "") End Function Sub LeaveNumbers() Dim cCell As Range For Each cCell In Selection If cCell <> "" Then cCell.Value = "'" & PullOnly(cCell.Text, "digits") End If Next cCell With Selection .NumberFormat = "0" .Value = .Value End With End Sub This code removes all text from the cell and leave all the numb...

Write result of function to a variable, where result could be an object

Write result of function to a variable, where result could be an object If I have a function which may return an object or a primitive type - within it I can do the following to handle those two cases: Function Result() As Variant 'may be object or not '... get item - the return value If IsObject(item) Then Set Result = item Else Result = item End If End Function However, how can I do the same test for the variable where Result is stored without running the function two times? Eg Result Dim myResult As Variant If IsObject(Result) Then 'test return type of function Set myResult = Result Else myResult = Result End If As myResult = Result 'fails if Result returns object Set myResult = Result 'fails if Result returns non-object I am trying to write a series of objects/non objects to an array of variant type I'm curious about the specifics where you wouldn't know what was being returned. In theo...

Excel VBA code to loop through folders, combine files, create graphs then save in a different location

Excel VBA code to loop through folders, combine files, create graphs then save in a different location I am trying to write some VBA code however I am quite new to it. Every month I need to make 40+ reports for different sites from csv files. So far I have code to combine csv files and make one graph, however I need to make two more graphs from files that have near enough the same name only similarity is the beginning of "SimHistory". My thinking was to get all of the csv files combine them per site, put that data into tables, then to create graphs from that and then to save them in a specified folder for these reports. Each site has its own folder with 4+csv files and there are around 40+ sites I am able to get one of the graphs and combine the files but I cant work out how to loop through all of the folders and achieve everything that I want. Any help or skeleton code would be greatly appreciated Here is what I have been using so far: Combine: Option Explicit Sub CombineFil...

Copy values from different workbooks into a master file

Copy values from different workbooks into a master file So, at my work I am trying to create a master file which copies information from a fixed cell from different Excel files into a Master file. these values need to be written in different cells that are in the same row, but different column. My code can read through the files but does not paste any values in the cells, here is my code: Do While MyFile <> "" DoEvents On Error GoTo 0 Workbooks.Open Filename:=MyFolder & "" & MyFile, UpdateLinks:=False Range("J23").Select Selection.Copy Windows("MasterFile1.xlsm").Activate For c = 2 To 13 Cells(4, c).Select Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _ :=False, Transpose:=False Next c 0 Workbooks(MyFile).Close SaveChanges:=False MyFile = Dir Loop What worksheet is J23 on in the recently opened workbook? What worksheet is the destination on the master workbook?...

Calling a macro (in Word document) from Excel macro using document name a runtime

Calling a macro (in Word document) from Excel macro using document name a runtime I need help in triggering a sub in a word document from Excel VBA. I want to use the Word document name at run time while calling the macro from Word document. I have done similar thing for PowerPoint and I want to replicate the same for word. Code snippet used for PPT: objPPT.Run "'" & StrPPTName & "'!ModuleName.Sub-Name", arg1, arg2 I am not able to do the same for Word, please suggest. "I am not able to do the same for Word" why not? What did you try for Word and why didn't it work? What errors did you get? – Pᴇʜ Jun 29 at 6:46 In addition to what @Peh says: Is this MAC or WinWord and which version of Office? Use the edit link below the question to add information or make any cha...

VBA Alert pop up for values in a column

Image
VBA Alert pop up for values in a column I'm trying to create a VBA -Alert pop up in a excel column. In the excel sheet based on certain calculation some Growth% (column H) will be calculated and if the Growth% > 20%, a alert popup would be generated asking for the Reason Code, which needs to be put in Column I. The code is working fine for a particular cell (say H7 ) but when I'm extending it for a range (say H7:H700 ), it's not working. Can someone please assist me regarding this. The code: H7 H7:H700 Private Sub Worksheet_Change(ByVal Target As Range) If Range("H7:H700") > 0.2 Then MsgBox "GR% >20%, Put the reason code" End If End Sub % growth Reason Code 34% 20% 18% The updated snapshot of the excel sheet: Now the ASM/RSM can update their forecast and automatically Growth % will be calculated in column H ...the same values will be copied in column I (as paste special) and if the Growth % > 20% , then the alert will pop...

copy rows multiple times (given in a cell) and add unique id number based on cells

Image
copy rows multiple times (given in a cell) and add unique id number based on cells I have a big table containing data like this one (ProductName, ProductId, RepeatNumber) I would like to create a new dataset on a new Sheet (Sheet2). The macro would copy data from Sheet1 and it would Insert rows as many times as it can be seen in the column C (the enclosed macro can already do that) but i would like to place these data on a new Sheet (Sheet2) and to give an ItemId in the Column B on the new sheet (on Sheet2) which is created by ProductID. The first 5 character of the ItemId is the same as the ProductId and the last two one is 01, 02, 03 and so on until the repeatnumber. Since these original data on Sheet1 are changing continously, that is new rows are added on Sheet1, i would like an input box for giving the rownumber from where the macro needs to run. The first data (created by the macro) would be placed in the last nonempty rows of the column A of Sheet2. First time the input value wo...