VBA Error When When Running SQL Against Excel Data

Jan 3, 2014

I have an Excel file with a table of data on Sheet1. The table of data has 3 fields which are Code (a Text field) , Date (a Date field) and Amt (a Number field). I'm using vba with sql code to query that table and return the results of the query to a different sheet in the same file. So just to reiterate, Excel is my data source. I've done my research and largely worked this code out.

I'm also plugging a date parameter into the WHERE CLAUSE of the vba/sql code and this date is drawn from cell D4. This way, the user can change the date in cell D4 and this will change the criteria in the WHERE clause of the sql query to give them the results they want.

However I am getting an error that reads 'Data type mismatch in criteria expression' when I run the below code, so there must be something wrong with the specific syntax I'm using to plug in the date from cell D4.

Note that I can get the code and parameter to work if I make the CODE field the parameter with the query definition line of :

query = "SELECT [Code], sum([Amt]) as Ttl FROM [Main$] WHERE [Code] = '" & Range("D4").Value & "' group by [Code]"

Sub Pull_Data_from_Excel_with_ADODB()
Dim cnStr As String
Dim rs As ADODB.Recordset

[Code]....

View 9 Replies


ADVERTISEMENT

Excel 2007 :: RunTime Error When Running Macro From Alternative PC

Aug 9, 2012

I am getting a "Run time error 5", "invalid procedure call or arguement" when I run a macro on a PC other tha the one on which it was created.

In this case both PC's are running on the version 2007 of Excel.

This is the highlighted statement when the macro fails

Code:
ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
"SOCX25!R1C1:R" & Lr & "C23", Version:=xlPivotTableVersion14).CreatePivotTable _
TableDestination:="SOCX25!R7C25", TableName:="PivotTable1", DefaultVersion _
:=xlPivotTableVersion14

View 4 Replies View Related

ERROR While Running Macro From Template

Feb 2, 2010

This code works well when I run it saved as an .xls. When I save the file as a template and then try to run it bombs on the very last line.

View 2 Replies View Related

Checkdate Error When Running Macro

Oct 3, 2012

I have a code to save a file. I've used it before so tried to adapt for current requirements. Seems I can't get around the "checkdate" as I get a "Compile Error: Sub or Function not defined" message.

Sub SavetoEst()
Dim strHeader As String
Dim i As Integer, j As Integer, k As Integer, l As Integer, m As Integer, n As Integer, x As Integer
Dim fs0
Dim f, getname, path
Dim fd As FileDialog
Dim fdfil As FileDialogFilters
Dim strFIlename As String
Dim strdate As String

[code]....

View 2 Replies View Related

Import Macro - Getting An Error When Running It

Apr 24, 2009

I tried to adapt this code into my own from another thread. [url]

BUT, I am getting an error when running it. On the "For i" line. And I know just enough VBA to be dangerous. Can someone help?

I have another code setup to run if a certain cell equals "October" then it calls ImportData. Then this code is supposed to pull all files out of My documents/TechConnect/October08 and place the data into sheet 1....

View 9 Replies View Related

1004 Error When Running Code ...

Aug 2, 2006

I want to place a message in cell

Sub OutOfStockDate()
templateSheet.Range("B15").value = dataSheet.Range("G5").value
If dataSheet.Range("G5").value = "" Then
templateSheet.Range("B15").value = "There is no Out of Stock Date"
End If
End Sub

However when I run this code I get the infamous 1004 error.

View 9 Replies View Related

Running Two Worksheet Change Scripts Gives Error

Jun 11, 2009

Running Two Worksheet Change Scripts Gives Error
I need to run two VBA scripts on the sheet1 tab:

View 2 Replies View Related

Getting Run Time Error 1004 When I Am Running This Macro

Aug 26, 2009

I am getting a run time error 1004 when i am running this macro. I got this macro to my earlier thread. As i am a beginner in a macro, I am unable to identify the problem. I have attached the workbook for the same

View 5 Replies View Related

Object Required Error When Running Macro

Apr 28, 2010

I am trying to run the following macro to copy a data range(A1:HX1) range from one sheet(sheet 6) and past it into the next available blank row in another sheet called New_Overall_Input_File but get the following error when I try and run it......."Object Required"?

Sub ALLCARS()
Sheet6.Range("A1:HX1").Copy
New_Overall_Input_File.Range("D" & Rows.Count).Offset(1, 0).PasteSpecial xlPasteValues
Application.CutCopyMode = False
End Sub

View 9 Replies View Related

Error With Running VBA Code Module For Another Workbook

Mar 13, 2012

I have a workbook which I regularly upload that cannot have macros within it; however, to update and process the data, I must utilize VBA Code.

I tried to work around this by storing my macros in a module in another workbook. My process is to have the VBA Code Module from the other workbook open and have the active workbook be the one I want to change, then I run the VBA Code from the other workbook.

This used to work. However, I am recently getting problems with the Code not running correctly. Sometimes it only runs the code if the affected cells are not hidden; other times it will not run the code at all!

View 4 Replies View Related

Error 800A9C68 Running VBS Using Task Scheduler

Aug 1, 2014

I keep getting this windows script host error.

Script: C op 5 macro.vbs
Line: 5
Char: 1
Error: Unknown runtime error
Code: 800A9C68
Source: Microsoft VBScript runtime error

Code:
Dim xlApp
Dim xlBook
Set xlApp = CreateObject("Excel.Application")
Set xlBook = xlApp.Workbooks.Open("S:OperationsDaily ReportsTop 5 op five macro.xlsm", 0, True)
xlApp.Run "WeeklyReports"
xlBook.Close
xlApp.Quit
Set xlBook = Nothing
Set xlApp = Nothing

View 9 Replies View Related

Error Running Macro When Sheet Is Protected

Sep 9, 2008

I am getting an error when I protect a worksheet and save it. Upon re-opening the worksheet, I try to use the cells that are being formatted by a macro, but I get the following error...

Run-time error '1004':

Unable to set the NumberFormat property of the Range Class.

If I open the worksheet and it is already protected from when I last closed it, then I get the error. If I unprotect the sheet, then close it and reopen it, then I don't get the error. Does anyone know what I might be missing or doing wrong.

View 9 Replies View Related

Runtime Error -2147417848 Running User Form A Second Time

Mar 28, 2007

I have a user form that builds a workbook from one template sheet and information in a SQL Server database. The template sheet contains 4 charts that are copied to every new sheet in the workbook, then their data ranges are set through VBA code. For a while the code was working wonderfully. All the necessary sheets were being generated and correctly populated.

Yesterday I added a new module to generate another sheet and pull data from the same SQL Server tables. Now if I run the userform it will work fine once and create all the needed sheets, and set all the charts to the proper ranges. However, if I delete all the created sheets and run the form again, I get:

Runtime Error '-2147417848 (80010108)'

Automation Error
The Object Invoked has disconnected from its clients

The error consistantly occurs for the following line of Selection.Copy Destination:=Worksheets("Master").Range("D1")

After the error the selected range still shows up as surrounded by a selection box, but if I change sheets, the box moves to the new sheet. Also I cannot select any new cells in the work book. In order to get Excel to work again I have to End Task from the Task Manager just to get it to close. When I restart Excel and go back to my work book I get the same results, i.e. The form works great once, then Excel dies.

I have tried qualifing all of the objects that can be qualified. I have tried setting all possible varriables to Nothing before exiting my macros. Nothing I have tried, or found suggested so far in the forum works.

View 9 Replies View Related

Error Formatting When Import Data From Google Into Excel

Feb 16, 2013

I use Google Spreadsheet to feed some data online. Later on I use Excel to import this data that it is hosted at Google to do a better handling (reports, charts, etc). However when I import the data from Google, the contents of 1 row is splitted on 4 in Excel.

Are there any way to keep the same formatting from the original ?

[URL]

View 5 Replies View Related

Excel 2013 :: Error When Sorting Data With INDEX Formula?

Mar 18, 2014

I've got large set of data(Column E) for dates from 2007 to 2013(Column B). Here dates are in chronological order.(Attachement) Now I want to match the data in to dates in Column H. Here dates are in random order. I used =INDEX(E3:E40582; MATCH(H3;B3:B40582; 0)). But it doesn't work.

View 5 Replies View Related

Excel 2007 :: Error While Copying Extracted Text File Data?

May 7, 2012

I am trying to develop a code which extracts the data from text files inside a folder (Folder test in my desktop) into one sheet. The Macro is in the workbook “Text Extract” which is an excel 2007 file. The data of each text should be copied to Sheet1 of this workbook one below the other. For testing purpose I have kept only one text file in the folder and was trying to copy the data from the text data extracted sheet to Cell A1 of Sheet1 of workbook “Text Extract”. The code works fine till copying the data, but shows below error in the line “Selection.Paste”:

Run time error 438: Object doesn’t support this property or method.

Below is the code:
Sub LoopThroughFiles()
Dim strFile As String
Dim strPath As String

[Code]....

View 6 Replies View Related

VBA Code Error - Extract Data From Multiple Workbooks To Single Excel Spreadsheet

Mar 28, 2014

I have a folder with multiples excel sheets

Destination : C: Project CustomerExcel

I would like to extract and compile the information contained in these cells:
a5,c5,a6,c6,c7,a14,g14,e16,g16,e18,i18,a20,g20,h22,j22,h24,l24 all the sheets.

New sheet would contain the information of each sheet eg. Column A2= file name

And Row B2 to R2 or whatever will be the corresponding cells mentioned above for each cell. The code I have only brings back the file name but only a5 from the range but not the rest.

VB:
Sub MergeAllWorkbooks()
Dim SummarySheet As Worksheet
Dim FolderPath As String
Dim NRow As Long
Dim FileName As String
Dim WorkBk As Workbook
Dim SourceRange As Range

[Code] .....

View 5 Replies View Related

Excel 2003 :: Getting 1004 Error While Copying Data From Sheets To Master Tab In The Workbook

Mar 12, 2014

I have attached a workbook (excel 2003), I have few userforms in it.

I tried to copy data from all the tabs in the workbook to "Master" tab but getting an error.

You have to login to file details are as below:

View 3 Replies View Related

Runtime Error 4065 - Pasting Copied Data From Excel To Outlook Email Body

Apr 24, 2014

I have a VBA excel file that pulls data from a CSV file downloaded from a link. I format this data into a table through excel and then copy it over to Outlook. This is where the problem is. I get a runtime error 4065 for "file is locked for editing".

View 1 Replies View Related

Possible To Have Running Tab In Excel?

Apr 11, 2012

I have an Excel document with about 40+ tabs that represent different categories of data that I input on different days. I was just wondering if it was possible to have another tab (in the same document) that could accumulate all the data from the other tabs into one sheet so I can see all the data for each day regardless of which sheet it is on?

For example, what I input into Sheet 1 also gets written in the "accumulated" tab and the same for other sheets? And if I delete something from one of my sheets, it also gets deleted on the "accumulated" tab.

View 5 Replies View Related

Running Excel Macros On Mac?

Mar 18, 2013

I currently use an Excel program (with macros) that run weather forecast data. It is compatible with versions XP, 2003, 2007 and 2010. However, I am trying to figure out if I can run it on a Mac. My plan is to run windows on my Mac through Parellels or VMWare Fusion.

Here is a link to the Excel Program: TX Tornado Forecast Worksheet

View 2 Replies View Related

VBA Running Faster Than Excel

Nov 6, 2009

I have discovered a strange problem with my VBA code. After testing it on several machines, I've found no problems with my workbook until now. After being run on a rather slow Windows Vista laptop, I've found that VBA appears to be running faster than Excel, and consequently it is creating errors as VBA asks Excel to do things before it has finished a previous action. This is causing macros to fail several times in each run, though can be solved simply by pressing 'debug' and then F5 to continue the code. Is there a way to get VBA to run slower to solve this? As I can't think of any other way of doing it? I've certainly not seen it happen on any XP or Win 7 computer!

View 9 Replies View Related

Users In Excel :: 50+ Running Slow

Dec 2, 2009

I have built an Application in Excel that is used by a userbase of 50+ people. Now, as standard, they are only able to access the document read only. The application writes data to an ".mdb" but the user cannot change the application directly istself.

Now, we've had the problem over the last few days that the program is running slowly when it is trying to write data back to the ".mdb" file.

I believe that it could be because connection to the sever that our application is running slowly (or the server is too highly trafficed) but our server team are telling me there is nothing wrong with the server and it's running slowly because there are too many people in one Excel application/

View 9 Replies View Related

Running Clock In Excel Cell Directly

Jul 17, 2014

How we can put a running clock in Excel Cell directly .

View 2 Replies View Related

Running Clock In Excel With Different Time Zone

Nov 28, 2013

Need running clock in Excel... in A1 I have put running clock which is taking current system time. However, I want to add running clocks for EST in B1 - CST in C1 and PST in D1.

VB code I used to display current system running clock

Global clockOn As Boolean
Sub runClock()
Range("A1").Value = Now()
If clockOn = True Then

[Code] ......

Attached File : Time.xlsm‎

View 3 Replies View Related

Excel Crashes Erratically After Running A Macro?

Mar 20, 2014

I have developed a model for a client which keeps crashing after being used a few times. The crash is major! Excel shuts down and asks to send an error report.

This can happen after being run anywhere from 3 to 20 times. (Clicking a POST button which transfers items to a "database" type sheet).

I developed the model on a PC using Excel 2010. When this was loaded on a Mac, the user tells me that it happened periodically, and I have seen is occasionally on my PC as well.

However, the workbook has now been loaded on a server, with users across the state of Victoria accessing via Sharepoint - most using Excel 2007. Now it is happening very frequently.

I don't think the macro is at fault, it doesn't go into debug. Excel just seems to GIVE UP.

Have you seen this kind of thing before? Is there a way of "flushing buffers" or something so that Excel can keep working?

I am reluctant to post the model because it is full of personnel details, and is 2.5mb.

View 6 Replies View Related

Excel 2007 :: Running Monthly Average

Jul 9, 2012

I would like to keep an average for 12 months.Each number entered for a month would be averaged with the total months with an entry until all 12 months had entries. I am using excel 2007

View 9 Replies View Related

Excel 2010 :: Running Total Sum Formulas

Apr 10, 2014

I Need to Understand Running Total Sum Formulas. I'm using Excel 2010. and I'm typing in the basic correct formula to arrive at a running total for each ajacent cell to the left of it.

I put in the correct formula in Cell (B1) of Sum=(A1)

I then put in the correct formula in Cell (B2) Sum=(A1:A2) I then highlight the A1 part of the formula with an F4 Key to lock it in.

I then drag the B2 Cell all the way down the excel page to capture all of my running total coming from the (A) Column just to the left of my formula.

Why even though I'm getting the answers I want in the running total does it put an error message in each of the correct answers in each of the cells in the (B) column where I put my formulas.

I tryed to delete the error message spot but I don't know how to delete all of the error spots without going into each cell one by one.

How can I get rid of all the error message out of each cell without having to click on each cell one by one to do it when I might have over 500 or more cells to click on.

View 9 Replies View Related

Running An Excel Macro Using VBA Code In Ms Access

Nov 13, 2006

I am attempting to run a MS Ecel macro that is stored on a MS Excel shared file in a MS Ecel target file (locally stored on my C drive) from a VBA module in Ms Access. That is, from a code i want to open the .xls file that houses the macro, and then open the .xls file that i want to run the file in, and then run the macro.

Here is my situation: the file that houses the macro has the workbook hidden and causes in error.

if i unhide the workbook i get a Run-Time Error 91...object variable or With block variable not set.

if i hide the workbook the vba coding can't find the macro...run time error 1004

once again, i currently have an excel file that houses macro whose workbook is hidden.

does anyone know how this can be accomplished?

here is the ....

View 9 Replies View Related

How To Keep Excel From Running A Macro From Another Open Book

Feb 28, 2009

I have several similar documents open. They each have a macro with the shortcut CTRL + SHFT + T. The problem is each macro is different for each book. When I am working on book X, I don't want macro from book Z to run, but it does.

I need all of them to be open.

View 9 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved