I am currently working on a project that uses Excel to parse a .txt document. Its working quite well for me. It functions by having two worksheets. In the first worksheet I use the " import external data" menu to import my .txt file. In another worksheet I have set up fields that show only the important information from the .txt file and leave the junk behind.
Iím looking to improve the functionality of this by adding a button to automatically clear the data in the first worksheet so that new data can be added quickly.
I have searched the forum and found a couple of threads on "QueryTables". After reading up on those, I have made a simple button with the following code.
After I load a .txt file and parse it using the formulas set up, I copy my needed information and then press this button. The cells clear, and the QueryTables are "reset" (maybe not the right word). Now a different .txt file can be imported and the process starts again.
The problem I am having is that. If there is no "QueryTables.Item(1)" to delete, I get a run time error. (Run-time error '9': Subscript out of range).
Would anyone know how to make my button conditional to having a "QueryTable" active? I.E. If I press it when there is no data loaded it doesn't do anything or give me that error.
What I required is either a Macro or Code for formulas in column 'F' in the attached spreadsheet that correspond to the SUM of each description and divided by 37.5 e.g. in F10 the formula should be =D10/37.5 the formula should be F12 D10/37.5 and so on all the way down the Pivot table
My problem is as the amount data increases on the Data Tab the formulas in column 'F' will become out of line with the corresponding Sum of each description so I guess I need some code or formula that check every time the Pivot table is refreshed.
Neither is it because you've turned SU off, and then used 'Select' or 'DoEvents' etc in your code.
When running an update for a QueryTable (once a second), 3 'buttons' (activeX image controls with code behind them) flicker - though I see no reference to selecting and/or screenupdating in my code
Is this purely something about refreshing a querytable that I can't fix?
Is there a subclass or API call I can intercept to stop drawing the images alone?
Public Sub ActivateConn()
Dim strFilespec As String Dim strConn As String Dim sqlStr As String
Set RecSet = New ADODB.Recordset
In short, there's no REASON why I couldn't just use the selection_change event to fire the same macros as the buttons but... well... it doesn't look anywhere near as good (I have a thing about making VB apps look as good as the code behind them is smart)
I have a website (National Lacrosse League - 2013 Regular Season - Standings), that I want to pull information off and automatically into Excel.
I have been using web queries on other websites, and they have worked beautifully, however the tables that I want aren't recognised by the web query wizard (no yellow/black arrows). I can import the whole page through a query, however that's not really practical.
Is there a way I can import just specific tables on this site?? I'd like both the 'east' and 'west' tables.
I'm trying to query a web site and export the data to a single sheet in Excel. I've used the record macro function in Excel (2007) and come up with the following but I want to query over 20 pages from this site and wondered if there was any way in looping this macro to do the hard work for me;
I don't have Excel 2013 so unfortunately I can't easily create relational data in Excel 2010. I'm looking for a solution to a design problem. I'd like to have 2 tables which I can join with Microsoft Query and run pivot table reports.
My department processes payments, both for internal clients and external clients. My Payments table looks like:
Date | Type (internal/external) | Operation (what type of payment) | Method (internet, mail, etc) | Quantity
Additionally, I have a table for Mail Opening, which looks like:
Date | Employee | Operation | Quantity
My overlapping fields are Date and Operation. Using each table individually, I can get nice pivot table reports. What I'd like to do though is be able to not just see what operations and methods were run each day with what quantities, but also to compare that to how much mail was opened. Employee and Operation is a multi-multi relationship, so when I join by date, I end up getting incorrect numbers because of problems with the data layout. I'm open to changing my data structure, as I know the way it's set up right now isn't great, but I'm having a mental block on how to redesign it. I attached a sample workbook.
I've tried to remove connections after saves and have been unsuccessful.
HTML Code: ' Delete Additional Connections ' If ActiveWorkbook.Connections.Count > 0 Then ' For i = 1 To ActiveWorkbook.Connections.Count ' ActiveWorkbook.Connections.Item(1).Delete ' Next i ' Else ' MsgBox ActiveWorkbook.Connections.Count ' ' End If
HTML Code: ' Remove named ranges For Each nm In ActiveWorkbook.Names nm.Delete Next nm
I've tried both of these and the Excel file is still attached with XML to the query table. I get an error message saying the format is different then if you click okay it shows its connected to the database still. Is there an aggressive command that will severe all connections before saving? What commands to run to stop this connection after save to another workbook?
I am developing some code to extract selected worksheets to a new workbook, and provide the data in a "standalone" form where certain formulas have been converted to values etc. As part of this project, hidden columns are made visible, then data is pasted as values on a row by row basis, then the previously hidden columns are deleted. Here is the code that unhides the columns and identifies those columns as ones that it needs to delete later on:
'Expose hidden columns and keep a list For i = 1 To 200 Range("a1").Offset(0, i - 1).Select If ActiveCell.EntireColumn.Hidden = True Then colnum = ActiveCell.Column ActiveCell.EntireColumn.Hidden = False If HideCOL <> "" Then HideCOL = HideCOL & "," & colnum Else HideCOL = colnum End If
The macro then goes about its business doing this and that, and at the end comes back to delete those offending columns whose numbers have been stored in the variable "HideCOL".
'Delete columns that were hidden If HideCOL <> "" Then Dim colArray As Variant .............
I have written VBA code which is operated every month. This code deletes several range names in a target spreadsheet, performs other actions - including extracting certain areas to different spreadsheets and then closes the spreadsheet without saving.
The range names in the target spreadsheet are required for ongoing use, so can not be deleted permanently.
Is there any code that deletes all range names in one go? At present my code includes the results of recording a macro wherein I delete each range name in turn - creating script over 100 lines long.
I have a spreadsheet (see attached) in which there are many series and i want to be able to delete most of the series except the first 4.
(The 0%, 5% 10% air voids and the 95% comp line)
iv got this code, which is attacted to a command button, which works fine to delete all the series but makes the graph a blank white box. id prefer it so it delete just the series not the graph "picture?" ...
I have a VBA Macro that loops through about 100,000 rows in an Excel file and removes rows that have a duplicate cell value. The macro takes about an hour and a half to run. Are there any ways to make the Macro run faster? Any ways in general to make VBA macros run faster?
I need an easy code that searches all of column A and deletes the entire row if the cell has the value "-". It needs to find the last row of data using something like LastRow = Range("A" & Rows.Count).End(xlUp).Row
What my excel sheet is doing is importing a bunch of data from a query. I have all my queries linked to buttons through macros. There are going to be 20-30 buttons that are linked to a query, and each query will produce a different amount of data(in this case, account numbers). When pressing a button linked to a query(i also have one 'Clear' button that just deletes the data, thats all), i use a macro to delete the previous query so it can import the new query into the same cell. The problem I am having is that when a button is pushed and there is no query, I am getting an error message. Here is my original code(macro), and the underlined code is where i am getting the error
I am using below code to delete the sheet from workbook.
For iTemp1 = Workbooks.Item(funEach.Name).Sheets.Count To 1 Step -1 Sheets(iTemp1).Select If UCase(Sheets(iTemp1).Name) "TEMPLATE" And UCase(Sheets(iTemp1).Name) "WORKING" Then Sheets(iTemp1).Delete End If Next
How can i avoid the below popup..
-Data may exist in the sheet(s) selected for delettion. To permanently delete the data press delete.
I am trying to import data from Yahoo, about half the time it works well, but the other half I get the Run-time error '1004' below.
Run-time error '1004': The file could not be accessed. Try on of the following: .. Make sure the specified folder exists. .. Make sure the folder that contains the file is not read-only. .. Make sure the file name does not contain any of the folloing charaters: < > ? [ ] : | or * .. Make sure the file/path name doesn't contain more than 218
I used a posted code to copy web query data from sheet2 to sheet1. Then a friend modified the code in order to Copy it to a new row in Sheet1 instead of a new column. The code works perfectly but I really wish that when the data is copied from Sheet2 to Sheet1 it will be only Values in order to keep my formulas and formats.
I read about .PasteSpecial xlPasteValues but I don't seem to find where exactly I should write it within the code.
with code in which I import data from the web via a query then try to use end(xlUp).row to find the last row of the query. Right now, the code continues while the worksheet still displays "Getting Data...", so the last row always comes out as row 1. After the data is finished importing, however, the last row is most definitely not 1.
If I put a break point after the query and wait for the data to finish importing, then let the code finish, it runs perfectly. But how can I have the code automatically wait to move on until the data is finished importing?
I have two tables of information. The first is a matrix with some distances. The second is a table of distribution. Ive been trying this for a long time now with limited success using a truth table but i've realised the only way to do this is in code. Ive got limited experience with this so please point me in the right direction.
Ive written some steps explaining what each table does here -
Step 1Check for lowest value B4:F4 in Table 1 (in example is 10) Step 2Check corresponding column destination available capacity in table 2 (Example 500) Step 3Distribute as much as possible from source in table 2 (500) Step 4Reduce value in capacity line by value taken from source Step 5If some source remains move back to table 1 and find next nearest column Dest Step 6Repeat step 2 until all source is gone in row Step 7 Check for lowest value B5:F5 in Table 1 if run out of capacity at all sites stop code etc until Table 1 column B is empty
Ive posted a spreadsheet with some before and after tables in it aswell. Its very small and formatted o its easy to see whats happening.
I looking for a solution to change a Access Query Criteria using a VB code in Excel, without opening the Access DB and changing the criteria manualy?
My normal Job is it: 1) I Work all the time in Excel 2) At the end of the work in Excel, I need to open Access 3) Open a query (Called "MyQuery") 4) Change one parameter the Date: Between 01/10/2008 and 30/10/2008 (This for each month) 5) Run the query
I looking to get rid of points 2) to 5) by replacing with a Command button on an Excel sheet
Dim mydbase As Object Set mydbase = CreateObject("Access.Application") mydbase.OpenCurrentDatabase ("C:My doucmentsDB1.mdb")
mybase."MyQuery"."Date Criteria" = Between (Worksheet("Sheet1").Range("A1").value) and (Worksheet("Sheet1").Range("A2").value)
>>>>>The above line of code I have problems to get right!
I have 2 drop downs that when changed, auto refresh all pivot tables. My problem is getting the columns to auto-adjust based on the refresh or change of the data in the pivot table. Listed below the code I have thus far for the auto-refresh on pivot tables. How to auto expand all columns simultaneously.
The pivot tables are based off of tables on a different sheet(TOS Tables). So the code listed below is in the table sheet, not the pivot table sheet (TOS Customer Level). So followup question will be, which sheet to put the auto-expand columns code?
VB: Private Sub Worksheet_Calculate() 'If data on this worksheet changes, refresh the pivot table Sheets("TOS Customer Level").PivotTables("PivotTable2").RefreshTable Sheets("TOS Customer Level").PivotTables("PivotTable5").RefreshTable End Sub
I'm trying to write a VBA script which will delete all rows in my Excel spreadsheet where Column I (which contains a status code) does not contain the word "Completed".
At the moment, I'm doing this the other way round: my script is able to search for entries in Column I which contain the status codes "Pending", "Awaiting Authorisation", "In Progress" etc and delete them. The idea is that when all those rows are deleted, I'll only be left with rows which have a status of "Completed". This works fine at the moment. However, the concern is that if a brand new status code is added to the data file, my script would be unable to pick it up and delete it. This is a small sample of the code I'm currently using (which deletes all the rows with statuses other than Completed):
Using Excel 2010. I'm writing a macro that sets up a workbook to be used for estimating at the beginning of a project. In the code I need to create multiple tables (formerly known as "lists") in the workbook. Then later in the code I need to refer back to those newly created tables. Currently, the code that creates the table is part of a loop that creates the table on many different worksheets. The problem of course, is that I have to name the Table, and then it won't create a table of the same name on the next sheet. Then, later in the code, I need to make adjustments to the table that was just created before looping to the next sheet.
Is there a way to create a table without giving it a constant name? Or by giving it a name that builds off of other info in the sheet? For example, I would be good with the naming the table after the sheet name: "Sheet1_Table" or such.
Code: Sub Auto_Open() ' Dim sht As Worksheet If Range("A1") = 1 Then