excel-2010

Creating Parameterized SQL Queries in Excel 2010 with VBA

丶灬走出姿态 提交于 2019-12-06 05:13:52
问题 I came across the following link: http://www.informit.com/guides/content.aspx?g=sqlserver&seqNum=135 In it, they list relatively simple code to query the SQL Database from Excel VBA. ' Declare the QueryTable object Dim qt As QueryTable ' Set up the SQL Statement sqlstring = "select au_fname, au_lname from authors" ' Set up the connection string, reference an ODBC connection ' There are several ways to do this ' Leave the name and password blank for NT authentication connstring = _ "ODBC;DSN

Compare two Columns and format matching cells with different colors

China☆狼群 提交于 2019-12-06 05:02:33
I would appreciate your help with the following: I would like to compare two columns, let us say Column A and Column B, **looking for duplicates**. If a value in Column A has a match value in Column B, I would like to format the cells of the same duplicate value with the color (the colors are random and different for each match). This is if `A12 = B30`, the color will be red. And if `A20 = B1`, the color is green and so on. If there is no match just leave it as it. That was only an example for red and green. let say you have two columns (A and B). A1 = 1000 A2 = 2000 A3 = 3000 A4 = 4000 A5 =

Loop through workbook slicer names using VBA

梦想与她 提交于 2019-12-06 04:48:38
问题 I have tried Googling and searching for this one but just can't quite get it. All I am trying to do is loop through the slicers on an activeworksheet and delete the slicer if it exists. At the moment I have 6 slicers sitting there. Previously I had ActiveSheet.Shapes.Range(Array("Market Segment Name 2", "Line of Business 2" _ , "Customer Name", "Product Group Name", "Product Type Name", "Product Code") _ ).Select Selection.Delete But this was no good if I had already deleted the slicers. Now

PivotTable Do not show subtotals

北城以北 提交于 2019-12-06 04:45:53
问题 I am converting a table into Pivot and then to a CSV file. I want to remove the subtotals of the pivot table. So far: this is my progress. MACRO CreatePivot: Sub CreatePivot() ' Creates a PivotTable report from the table on Sheet1 ' by using the PivotTableWizard method with the PivotFields ' method to specify the fields in the PivotTable. Dim objTable As PivotTable, objField As PivotField ' Select the sheet and first cell of the table that contains the data. ActiveWorkbook.Sheets("Employees")

Workbooks.Open returns different file than Filename

有些话、适合烂在心里 提交于 2019-12-06 03:06:58
问题 I am having the strangest problem. I was writing the below code on my laptop the other day and it worked fine. Now, I am testing it on my desktop and it's stopped working. First, here's my code Dim oApp As Application Dim oWb As Workbook Set oApp = New Application oApp.Visible = True Set oWb = oApp.Workbooks.Open(Filename:="C:\myFile.xlsx", ReadOnly:=True) debug.print oWb.name 'returns "SOLVER.XLAM" ' "SOLVER.XLAM" is not "myFile.xlsx' debug.print oApp.Workbooks.Count 'returns 1 debug.print

Re-enable VSTO add-in that is disabled by the Application due to multiple errors

送分小仙女□ 提交于 2019-12-06 03:02:45
问题 I am writing and debugging an Excel VSTO Ribbon addin and it sometimes crashes due to errors in code. When Excel finally decides it's too much and asked me whether I want to permanantly disable it, I ACCIDENTALLY clicked yes. Now no matter what I do, I cannot get the addin to automatically load on Excel startup. I go to COMs AddIn dialog and set the checkbox; deleted the registry settings manually; cleaned the project in Visual Studio and rebuilt it -- no use. Where should I configure to make

EXCEL Reference a cell in the previous visible row

假装没事ソ 提交于 2019-12-06 02:49:23
问题 How can I reference a cell in the same column in the previous visible row from a filtered range? 回答1: This is very easy if we prepare to do it. Say we have data like: The first step is to introduce a "helper" column. In E2 we enter: =IF(SUBTOTAL(3,A2:A2)=0,MIN($E$1:E1)-1,SUBTOTAL(3,$A$2:$A2)) and copy down: Now the cool thing about the "helper" column is that no matter how you filter it, it always shows a simple sequential sequence....let's filter for Alice This means that any cell can:

Protect Excel Worksheet For Read Only But Enable External Data Refresh

那年仲夏 提交于 2019-12-06 02:49:23
问题 I have an Excel 2010 workbook. One worksheet imports data from an external data connection (SQL query). I have also added additional columns to the worksheet to perform calculations on the data and to massage it a bit. The worksheet forms the backbone of the raw data used in the other worksheets. I'd like to protect the worksheet to make it read-only (allowing sort, filter, pivot table usage). I know how to do this with the protect worksheet feature. But when the worksheet is protected, I can

Excel VBA; Updating a connection string

雨燕双飞 提交于 2019-12-06 02:24:22
I'm just trying to get VBA to update an OLEDB connection string. When I step through the code, I don't get any errors but the connection refresh fails and when I examine the connection string in the UI, it's obvious that my code has not changed it at all (hence the refresh failure). What have I missed? Here is the code: Sub UpdateQueryConnectionString(ConnectionString As String) With ActiveWorkbook.Connections("Connection Name"). _ OLEDBConnection .Connection = StringToArray(ConnectionString) End With ActiveWorkbook.Connections("Connection Name").Refresh End Sub The ConnectionString being fed

Filter table in excel VBA based on a column of values

只愿长相守 提交于 2019-12-06 00:40:46
问题 I have a table and I would like to filter the rows by the values in one of its columns. The values used to filter are stored in a separate column not in the table. This is what I have so far: Dim table1 As ListObject Dim range1 As Range Set range1 = ActiveSheet.range("AM23:AM184") 'get table object table1.range.AutoFilter Field:=3, Criteria1:=??? I do not know what to put for criteria1. I know it needs to be an Array and I can set it to something like Array("12","2","13") but what I need it