Syntax Error
Aug 27, 2009what is wrong with this syntax:
View 2 Replieswhat is wrong with this syntax:
View 2 RepliesI'm getting the error for the following piece of code.
Sub itconfandscratch()
Dim Cn As ADODB.Connection
Dim Server_Name As String
Dim Database_Name As String
Dim User_ID As String
Dim Password As String
Dim SQLStr As String
Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset
Server_Name = "sturecord"
Database_Name = "Scratch" ' Enter your database name here
SQLStr = "SELECT stuname FROM dbo.sturec" ' Enter your SQL here
Set Cn = New ADODB.Connection
Cn.Open "Driver={SQL Server};Server=" & Server_Name & ";Database=" & Database_Name & ""..............
VB:
Selection.FormulaArray = _
"=IF(RC[-7]=""Weekly"",RC[-1],IF((ParentCode=RC[-10])*(ClassType=""Active""),IF((EndDate=EOMONTH(EndDate,0))*(RC[-7]
={""Monthly"",""Quarterly""}),RC[-1],0),IF(RC[-7]=""Daily"",IF(SUMPRODUCT(((ParentCode=RC[-10])*(FundType=""C"")*
(ClassType=""Inactive Class"")*(TermDate<>"""")*(TermDate>=StartDate)*(TermDate<=EndDate))+((ParentCode=RC[-10])*
[Code] .....
I recorded macro for this formula its giving me syntax error i did " _" after the break but its still not working..
"Compile error - Syntax Error"
and the following line highlighted in yellow
"Sub CreateWorkbooks()"
It worked on Excel 2000 but not now and dont work either in Excel 2007.
Heres the complete code .....
Getting a syntax error which and I'm not sure what I've done wrong. This is the bit thats causing the problem:
View 2 Replies View RelatedIf I copy "mysum" contents to a cell and replace "lista" with a defined list, it works just fine. But whenever I run this code, it gives me syntax error.
Sub aaa()Dim i As Integer, myvar As Variant, tester As VariantDim mysum As Variant, lista As Variant,
alpha As Datelista = Sheet2.[D6].ValueWith Worksheets(Range("A10").Value) Do
i = i + 1mysum = Evaluate("SUMPRODUCT(((ISNUMBER(MATCH($B$8:$B$10007," & lista & ",0)))
*($A$8:$A$10007>(TODAY()-180))*(($E$8:$E$10007)+($F$8:$F$10007)+($G$8:$G$10007)+($I$8:$I$10007)+($K$8:$K$10007)))))
myvar = Evaluate("=TIME(10,0,0)>" & mysum) Loop Until myvarEnd Withtester = 35 - Sheet2.[c10]
alpha = mysumMsgBox "VALID for [" & lista & "] after " & i & " Day(s).
hours in last 180 days after " & i & " Day(s) will be (" & alpha & ")"End Sub
When running a Macro I am getting an error message as follows:
Run-time error '1004':SQL Syntax error
The line of code which appears to be effected is:
.refresh Backgroundquery:=False
I dont really know what this part of the code is trying to do and why it is highlighted yellow when I try and run the code. I am basically importing data from Access to Excel and this line is the last line of the code. If I remove this line, the error does not occur and the code completes. However, the data from Access is not imported so I am assuming it is an important part of the code!
I am having some issues with my macro. I keep getting a syntax error? I am trying to combine these coding combinations together. Code G0398 with 95800, code G0398 with 95801 so on so fourth..
G0398
95800
G0399
95801
G0400
95805
[Code] ...........
I need to insert rows in row A44 depending how many cells exits in a range i named "ALL_C"
I saw this code that inserts 10 rows on A44 so i thought by modifying it the way i did would work but it didn't. I'm still new at this stuff. What am i doing wrong?
Original
Sub Insertinrow43()
Range("A44").Resize(10, 1).EntireRow.Insert
End Sub
Modified (doesn't work)
Sub Insertinrow43()
Range("A44").Resize(Count(All_C), 1).EntireRow.Insert
End Sub
Thank you!
I'm trying to write a macro that will insert a excel formula into a specific cell. When I try to run the macro I receive a compile/ syntax error. I don't understand why as the formula works in excel. Here is the code (formula only)
View 4 Replies View RelatedOne of the formulas list whether or not an item is available or not. But when I try create a similar formula to indicate whether the item should be displayed or not I only end up with it being always displayed.
Code:
Option Explicit
Sub Reformat()
Dim wks As Worksheet
Dim iRow As Long
For Each wks In ActiveWorkbook.Worksheets
[Code] .......
what would be the correct format?
I know you can use the syntax range(cells(x,y),cells(z,w)) but for some reason unknown to be the following isn't working:
Set CurrSuppRange = TT.Range(Cells(1, CurrSuppCol), Cells(LastRow, CurrSuppCol))
where
CurrSuppCol = cboxCurrSupp.ListIndex
OurSuppCol = cboxOurSupp.ListIndex
LastRow = Workbooks(lbWkBkName.Caption).Worksheets(cboxWorksheet.Value).Cells(Rows.Count, "A").End(xlUp).Row
(each return integer values)
Set TT = Workbooks(lbWkBkName.Caption).Worksheets(cboxWorksheet.Value)
(tested and works fine)
I was able to get VBA to post this relative reference, which sticks the formula
=DATE(YEAR($D2),MONTH($D2)+6, DAY($D2)+1) into a cell in Col J.
All fine and dandy, works as it should with this formula.
Code:
.Cells(Row, "J").FormulaR1C1 = "=DATE(YEAR(RC4),MONTH(RC4)+6, DAY(RC4)+1)"
However, when I try this with a different formula =IF(ISNUMBER(SEARCH(C2,H2)),"REPEAT","SAFE"), I'm getting a compile error: Expected end of statement with this code:
Code:
.Cells(Row, "I").FormulaR1C1 = "=IF(ISNUMBER(SEARCH(RC3,RC8)),"REPEAT","SAFE")"
The error message highlights the word REPEAT. I suppose it's something with all the quotes throwing off where compiler thinks the end of the formula should be.
I get syntax error on return statement. I am using Excel 2010.
View 2 Replies View RelatedThis line fails, is Method Range Global error.... What is wrong w/ this, and how should it read?
If Range("D", i).Value = "Need Parent" Then
2nd Question- The following line is my normal method in doing a simple For Next Loop. What is the difference between using this one, looping through the cells and the first one referring to a Range for the loop?
If Cells(i, "D").Value = "Need Parent" Then
I´m writting a macro. It works find until a certain point. When I want to change some outputs of the macro without changing the syntax, it display an error mesage while runing the macro. It says Else without If. Which is quite disturbing because the Else was not creating any problem before. Here is my macro before I changed the conditions (this one work nicely)
Sub Copy_Sheet_Beta()
Set wba = ActiveWorkbook
On Error Resume Next
If IsWorkbookOpened("Projekt.xls", "C:Documents and SettingsfrederikSkrivebordRedd Barna") Then
Workbooks("Projekt.xls").Activate 'In case open, just activate "Projekt"
Else
Workbooks.Open Filename:="C:Documents and SettingsfrederikSkrivebordRedd Barnaprojekt.xls"
End If
Set wb = Workbooks("Projekt.xls")
wb.Activate
If Not SheetExists(wba.ActiveSheet. Range("C1").Value) Then
MsgBox "overall doesn't exist!"
Else........................................
Im having problem with If/Then/Else Statements Not sure what the problem is. I have a text box a user inputs whatever in to create two new tabs one is the tab name then the next is tab completed. It isnt liking my syntax I have here.
View 7 Replies View Relatedif I copy and Add it created a new workbook not the current on im in. What am I doing wrong?
View 5 Replies View Relatedtrying to write a formula in a VB to some cells:
View 3 Replies View RelatedI would like to have an email generated when a cell changes to a particular value. I've developed the macro to send the email with a saved attachment.
When I try to OJT-Engineer the text for the module, I can't get it to recognize the macro. It's a syntax issue, it seems.
What I need is for my module to initiate a macro when a cell changes to a value.
This is the code EXACTLY as it appears:
A theoretical question following an empiric result.
For the command “SendKeys”, for instance, take these two lines:
What is wrong with the syntax of this formula?:
COLUMNS(INDIRECT("AverageDemand!$A7:"&A$7))+4
I'm getting #REF errors and I can't work out why...
I have the following code that loops thru and puts the word 'TEST' in column J if column B has a TEXT value of '020'
----------------------------------------------------------------------------------
With Range("J1:J" & Lastrow)
.Clear
Range(.Cells(2), .Cells(.Count)).Formula = "=if((b2)=""020"",""TEST"","""")"
End With
----------------------------------------------------------------------------------
Questions
1) why do I need double quotes "" "" on every argument in the function? Is it because I'm working with TEXT data?
2)I want to use multiple ifs (ie if cell b2 equals '020' OR '030' then put the word 'TEST' in col J). How to change the syntax to do this?
I know this syntax isn't right.
I have a form and a combo box that I want ot fill the items in from cell F22.
Here is my
Sheets(PowerAnalysis.xls).Cells("F22").Value = ComboBox2.Text
What is the best way to get this done? I have searched here and on the web and I can't seem to find any straightforward answers.
I am trying to get the below autofilter working but to no avail, its just putting the text datStart and datEnd in the auto filter, not what I receive in the boxes, see bold line for line in question
Dim datStart, datEnd As Date
Dim strAgent As String
datStart = txtStart.Value
datEnd = txtEnd.Value
strAgent = txtAgent.Text
Range("A4").Select
Selection.AutoFilter
Selection.AutoFilter Field:=4, Criteria1:=">datStart", Operator:=xlAnd, _
Criteria2:="<datEnd"
I thought I saw a thread where someone used AutoFilter as a one liner like
Range("VFILTER").AutoFilter 23, "True"
but for some reason this does not work. The filter is active, but it doesn't pay attention to the field or criteria part.
In VBA Excel 2000 while ODBC connecting to a dbase file:
parameter=" N0011"
...
ActiveSheet.QueryTables.CommandText = Array( _ ...
"SELECT ... & Chr(13) & "" & Chr(10) & _
"FROM ... & Chr(13) & "" & Chr(10) & _
"WHERE (dbase_file.field1=" & chr(34) + parameter + chr(34) & "... & Chr(13) & "" & Chr(10) & _
"ORDER BY ...")
...
It doesn't work any more in Excel 2003. Of course it works directly such as:
"WHERE (dbase_file.field1=' N0011')
but I couldn't find the way to replace the ' N0011' with the parameter.
It is not the singular issue...
"FROM dbase.file dbase.file " that worked well in Excel 2000, the Excel 2003 "wants":
"FROM 'drivepath'dbase_file dbase_file "
and I couldn' find a way to replace the explicit 'drivepath' with a predefined variable.
I am trying to figure out what a past employee's macros do and how they do it. I would simply like to know what the followin syntax enables you to do:
While ActiveCell <> ""
...
...
Wend
or
While ActiveCell. Offset(5) <> ""
...
...
Wend
[Code] ......
I seem to be having trouble with the syntax the number range after (iPopFreqMax).
I am attempting to create a macro that opens a file named "shrinkage-billing.xls", searches for a variable "PTOSH" in column A, copies the adjacent cell and pastes the data in another worksheet named "Shrinkage Report 2009.xls"
The code follows ...