VBA With If Statement Syntax

Jan 21, 2009

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?

View 9 Replies


ADVERTISEMENT

If Statement (check Syntax)

Jan 24, 2010

I want to check something syntax wise about IF Statement
My line of code is as follows

View 2 Replies View Related

String Sql Insert Statement Syntax

Jul 16, 2009

In excel macro, I am trying to input data into sql server from excel ADO
what is the correct syntax for an insert statement using string sql? This table has two columns supplier ID autonumber and desc as varchar.

View 2 Replies View Related

Writing To File May Require Special Print Statement Syntax

Jan 22, 2013

Code:
' write data to txt file
For j = 1 To 3
For k = 1 To 21
Print FNum, OPTOarray(j, k)
Next k
Next j

I am writing an Array to a text file but I keep getting an error that the Print statement requires a suitable object. I tried Debug but all this did was put the data into the immediate window and created a file that was empty.

"????.Print FNum, OPTOarray(j, k)".

The data in the immediate window is correct but when you open the text file with notepad there is nothing to be seen.

View 1 Replies View Related

If Else Syntax: Change Some Outputs Of The Macro Without Changing The Syntax

Jul 19, 2006

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........................................

View 2 Replies View Related

Utilize A Select Case Statement In Target Intersect Statement

Jul 28, 2009

I am currently using an Intersect statement in a worksheet module to perform two things:
1. Insert a time stamp into row 2 when row 1 has a price inserted
2.To clear that time stamp if the price is deleted at some later date.

My problem is with the time stamp value being deleted by the user.
If I try to clear the price (now that the time cell =empty) I get a Runtime error 91 - Object Variable or With block variable not set.

I would like to convert this code to a select case statement but I'm not sure how to do this in this situation. Would error coding be appropriate in this instance?

View 5 Replies View Related

IF/Then/Else Syntax

Nov 25, 2008

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 Related

Creating New Tab Syntax

Nov 25, 2008

if I copy and Add it created a new workbook not the current on im in. What am I doing wrong?

View 5 Replies View Related

Getting A Syntax Error

Jan 28, 2009

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 Related

Looking For Correct Syntax

Feb 10, 2009

trying to write a formula in a VB to some cells:

View 3 Replies View Related

Syntax Error

Aug 27, 2009

what is wrong with this syntax:

View 2 Replies View Related

Module Syntax

Dec 1, 2009

I 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:

View 9 Replies View Related

Syntax For SendKeys

Jan 10, 2010

A theoretical question following an empiric result.
For the command “SendKeys”, for instance, take these two lines:

View 14 Replies View Related

Syntax Of This Formula

Sep 17, 2008

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...

View 9 Replies View Related

Combo Box Vba Syntax

Nov 18, 2009

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.

View 9 Replies View Related

VBA Autofilter Syntax

Apr 23, 2006

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"

View 2 Replies View Related

Autofilter Syntax

Dec 19, 2006

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.

View 5 Replies View Related

Vba Sql Syntax 2003

May 23, 2007

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.

View 3 Replies View Related

Syntax Of Loops

Feb 2, 2008

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

View 3 Replies View Related

Number Range Syntax In VBA?

May 4, 2014

[Code] ......

I seem to be having trouble with the syntax the number range after (iPopFreqMax).

View 1 Replies View Related

Copy Destination Syntax

Oct 17, 2008

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 ...

View 8 Replies View Related

Activesheet Copy Syntax

Jan 22, 2009

Got a wee problem with some syntax for a copy function. At the moment the code i have copies the range and pastes to another range which is defined by a cell number. But i need it to paste special (values only).

View 5 Replies View Related

Need Learning Resources For VBA Syntax

Mar 24, 2009

I would like to know where can I find a good resource to learn about VBA syntax. I have VBA books and there are some examples of code in there but when I'm trying to read someoneelse's code I just get into commands or syntax I don't understand. For example I would like to be able to go some site and decifer what this line (or it's parts) means: If(cnt < MAXTEST, sDigSep & String(MAXTEST - cnt, "9"), "")

View 4 Replies View Related

Syntax For Format TextBox

May 10, 2009

Is there proper syntax to combine these two lines of code into one line?

View 2 Replies View Related

Syntax For Variable Array

Aug 11, 2009

I have a variable array, that is, the first cell of the array is variable and the last cell is variable. I have dimmed the first cell , "firstcell" as a range. I have dimmed the last cell , "lastcell" as a range. I'd like to sort the array but first I have to select all cells in the array. Need the proper syntax to select all cells between "firstcell" and "lastcell" in my macro.

View 2 Replies View Related

SUMPRODUCT Syntax With Variable VBA

Dec 14, 2009

I need syntax using SUMPRODUCT. I have these two lines of code

View 2 Replies View Related

Sumproduct Syntax:. Don't Say 'yes', For Each Service

Jun 23, 2009

I have a large spreadsheet like this

NephrologyPrinted resent 26.05.09 chased
Nephrology28.04.09 resent 26.05.09Yes
Nephrology28.04.09 resent 26.05.09Yes
Nephrology28.04.09 resent 26.05.09Yes
Nephrology28.04.09 resent 26.05.09Yes
Nephrology28.04.09 resent 26.05.09Yes

There are plenty of other columns, but these are key. The first column is the service type, of which there are 40. I want to have another worksheet that totals all the entries in the third column that don't say 'yes', for each service. So, in this case the first line of my new workbook would say: Nephrology1

View 4 Replies View Related

Syntax Error Using Evaluate In VBA

Jul 28, 2013

If 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

View 3 Replies View Related

VBA Break All Links Syntax?

Jun 24, 2014

I'm looking for syntax to break all links in a workbook using VBA. I've found the below through independent research but I'm receiving a type mismatch error.

Code:
Sub BreakLinks()
'Macro Purpose: Break all links in the active workbook
Dim vLinks As Variant

[Code].....

View 1 Replies View Related

Indirect Function Syntax

Feb 15, 2007

Always have problems getting my head round the syntax of the indirect function and am unable to find anything similar that's been asked.

I want to perform an operation on two numbers where the user selects which to use (add, subtract, multiply or divide) entered into another cell like this:

******** ******************** ************************************************************************>Microsoft Excel - 200701 - LCC.xls___Running: 11.0 : OS = Windows XP (F)ile (E)dit (V)iew (I)nsert (O)ptions (T)ools (D)ata (W)indow (H)elp (A)boutC3C5=
ABCD14+5*2****3Normal*9*4****5Indirect*#REF!*Sheet3*
[HtmlMaker 2.42] To see the formula in the cells just click on the cells hyperlink or click the Name box
PLEASE DO NOT QUOTE THIS TABLE IMAGE ON SAME PAGE! OTHEWISE, ERROR OF JavaScript OCCUR.

View 9 Replies View Related







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