# The Logic Of OR: IF Statement That Will Evaluate Whether A Variable Is Equal To Any Of The Three Punctuation Marks ".", "?", Or "!"

Apr 16, 2009

tell me which operator works in VBA the way the OR operator works in functions? I want to write an IF statement that will evaluate whether a variable is equal to any of the three punctuation marks ".", "?", or "!". But I'm not sure how to code it. I attempted the following:

## Evaluate A Count Statement With A Variable?

Jul 14, 2013

I am trying to perform a count statement in VBA as below, with the 1st Evaluate I get the correct response, however with the second option it shows a 0. The variable is obtaining the correct values as per the example of 6017Complete, this is proven with the MsgBox

VB:
Dim TillNo As String
TillNo = Target.Offset(, -1) & Target.Offset(, 0) & "Complete"
MsgBox "Till Number is" & TillNo
Target.Offset(, 10) = Evaluate("COUNTIF(C3:C123,""6017Complete"")")
Target.Offset(, 11) = Evaluate("COUNTIF(C3:C123,TillNo)")

## Number Comparison And Logic Statement

Feb 8, 2007

I'm having a problem with coming up with a suitable excel formula. I have a table that calculates 2 values. Once these values are derived I need them to be compared to a separate table. This is how it works.

Table 1:
Cell B8 gives me total weight: 3187pounds
Cell C9 gives me the center of gravity in inches: 142.02

on sheet2
Table 2: Cell A2-A26 have weight increments every 50 pounds starting at 2200.
Cell B2-B26 have the minimum C.G. limit
Cell C2-C26 have the maximum C.G. limit

My question is how can I write a formula that takes the weight from B8 and compares it to the cells on sheet two (rowA) and finds the closest weight. Then from there finds out if my C.G. from C9 is within limits of my min and max values?
Sounds complex but it's not that bad. I'll upload the file to my website and let people download if they'd like to see it.

## IF Statement To Evaluate Multiple Cells

Jun 9, 2014

I have a ss that has item descriptions, quantities and pricing.

Item descriptions are identified by a letter (a, b, c, etc) and in cells C20:c32. These are selected by drop down box. Item quantities are in cells E20:E32.

I want to evaluate cells C20:C32 and determine what letter is chosen. If A is selected in any cell C20:c32 I want to count the quantities for A in cells E20:E32. I can't quite figure out how to do this.

## Force If Statement To Evaluate Another Formula Value

Aug 26, 2009

I am trying to use an If statement and wanting to evaluate another formula.

The formula is as follows: =IF(B6>=7,Table!M16,Table!M47) where B6 =REPLACE(D24,1,3,"") which returns an integer. In this case it is 6.

Unfortunately it doesn't process the formula value correctly in the If statement unless the reference cell is hard coded with the integer. Is there a way to force the formula to evaluate the value of the cell formaula first before doing the If comparison?

## To Insert A Variable Between Quotation Marks

Apr 21, 2009

I have the following line of
Selection.AutoFilter Field:=1, Criteria1:="=2009_15", Operator:=xlAnd

The highlighted portion is going to change from week to week. I have never been able to put a variable inside of quotation marks. I am sure it is simple, which explains why it is out of my mental grasp. how I can assign a variable in there?

## IF Statement Logic In Columns - True / False

Mar 31, 2014

Column A: T/F
Column B: True/False

Here's what I want in a sentence: If one of the cells in grouped row is "T", column B = True, if not then column B = False.
(row groups are separated by a blank row)

Example)
Col A,Col B
TTRUE
FTRUE

[Code] ....

I came up with following formula:

=IF(MATCH(TRUE,INDEX(ISBLANK(A1:A17),0),0)>MATCH("T",A1:A17,0),TRUE,"")

It checks to see if blank cell is found before "T" but it doesn't look rows above.

inincubus.grouprows-1.xlsx

## IF Statement Is Breaking Logic In Picking The Right Strcode Value

Jan 28, 2010

my IF statement is breaking logic in picking the right strcode value.

## Saving Final Date With Logic Statement

Apr 28, 2014

I have a workbook that is titled "Results". It has 2 columns that I need, a 'status' column (B) and a 'finalized date' column (C)

Column B is the 'status' column: Formula: ('[May Database]Summary'!\$B\$1)

The May Database B1 column is a dropdown with options "In Progress" and "Final" that will be switched manually.

The results workbook pulls it's status from the May Database workbook.

So I need my results workbook to update it's 'finalized date' column (C) when the May database says "Final" but populate and save the day that the May database was manually switched to 'Final'

My question is would this formula work?:

Results workbook status column: C1= IF(B1="Final", Now(), "")

Would this save the date when the May Database was manually switched to 'Final' or will this just update my current day everytime I open this workbook since Now() returns current day? Is there a way to save a date when it was finalized and then keep that date?

## Take Logic (IF) Statement And Implement It As Format For Array Of Cells

Jul 17, 2013

I have a list of data for each year dating back 10 years and some of lists had entries that weren't available so the cell showed up #N/A. I searched and replaced them with 0 but when I graph the data it skews my graph. I was wondering if it was possible to take a logic (IF) statement that says if the cell = 0 then take the average of the next and previous data points so the graph looks smooth. i.e. =IF(G444=0,(G443+G445)/2,G444) This gives me the correct number i want, but i want to apply it to all my lists like a format if possible.

## Nested Next Loop: Evaluate The If Statement Below Over A Range Of Cells

Aug 22, 2008

I think the problem is the order in which I have the "next" loops. I would like to evaluate the if statement below over a range of cells

Sub Analysis()

Dim i As Integer
Dim x As Integer
Dim y As Integer
Dim k As Integer
Dim TheLast As Integer

TheLast = Sheets("Name").Range("c" & Rows.Count).End(xlUp).Row

For i = -7 To -26 Step -1
For x = 24 To 43
For y = 14 To 43
For k = 16 To TheLast.................

## VBA - Remove Double Quotation Marks Around String Variable?

Jul 29, 2012

I would like to query your knowledge database (too much VBA I guess ) as I have a predicament that I cannot seem to solve.

Here is the thing: I am trying to write a sub that would enable me to automatically put in place extensible name ranges (the Offset worksheet function).

The problem is that, despite everything seems to go well, the reference in the name box displays : ="DECALER(\$C\$2;0;0;5-1;1)" (the string comes from a variable and Decaler is Offset in French). These quotation marks are the culprits for sure, as taken off the formula works beautifully.

I've tried everything I've found on the internet, that is to say: Replace(String, Chr\$(34), "") so on and so forth, but these marks are not recognized a part of the string so they escape the replacement.

## Evaluate Sumproduct With VBA & Variable Row

Feb 5, 2009

I cant see the wood for the trees! I have this formulae which works just how I want

ACO2 = Evaluate("= SumProduct((K2:K3=""Closed"") * (EG2:EG3=""06-15 Days""))")

However when I change this to a dynamic range I keep getting a syntax error. Can anyone see where I have gone wrong? I know its probably only a " or an ) out of place but its driving me mad!!!

ACO2 = Evaluate("=SumProduct(((Range("K2:K" & Lrow)=""Closed"") * ((Range("EG2:EG" & Lrow)=""60 Days+""))")

AC02 is an integer, as is Lrow (its a simple loop which works out how many rows there are).

## Pass Variable To Evaluate Worksheet Function

Nov 15, 2013

I understand that the SumProduct doesn't have the same capabilities in VBA as it does in worksheet formulas. I am trying to construct it in an evaluate statement in VBA but the problem is I am using it in a userform, so the conditionals are passed from two combo boxes. Here is the worksheet formula

Code:
=SUMPRODUCT((Table1[Home]=C3)*(Table1[Away]=M3)*(Table1[Goals (H)]>Table1[Goals (A)]))

The values C3 and M3 refer to a cell known as "Home" & "Away". It's comparing to the two teams selected to a table with game stats to show wins and losses. The user form has a combo box list with those teams. Combo Box 1 passes to a variable known as hTeam and Combo Box 2 passes to a variable known as aTeam. I need those values passed through to C3 and M3. Here's what I constructed but get a type mismatch

Code:
Evaluate("=SUMPRODUCT((Table1[Home]=" & chr(34) & hTeam & chr(34) & ")*(Table1[Away]
=" & chr(34) & aTeam & chr(34) & ")*(Table1[Goals(H)]>Table1[Goals(A)]))")

## If / Then Statement - C2 Should Be Equal To S2

Jul 18, 2012

If/then statement:

Trying to say if C2 is equal to Fee, Fixed, then C2 should be equal to S2.

Was trying to use

=IF(c2=Fee, Fixed,c2=S2,C2)

but, don't think I have it quite.

## If Statement (equal To And Greater Than)

Aug 24, 2009

If A7 is equal to and greater than 95% than B7 is equal to "A". If A7 is equal to 91% but less than 94.99% than B7 is equal to "B"...

## IF Statement To Search If Value In Cell Is Equal To A Value In Range

Jul 2, 2014

I want to create a simple if statement to search if a value in cell B2 is equal to a value in the range 'CodeCheck'!A1:A92

I have written the code =IF(B2='CODECHECK'!A1:A92,"Y","N")

I am always getting N returned even though I am 100% sure the data in B2 is in the 'CODECHECK'!A1:A92 range.

## Add Punctuation To VLookup Macro?

Nov 30, 2013

I have the below code that performs a Vlookup. What I need to do is enclose the value that has been looked up into single quotation marks, one at the beginning and one at the end.

Sub SourceVLook()
Dim LastRow As Long
Dim LookupRange As Range

[Code].....

## VBA To Remove Punctuation And Spaces

Jan 23, 2008

I need VBA to remove all punctuation and spaces from cells. What I want is to do this from the same columns every spreadhseet that I open and when it gets to row 700 to stop. So I guess a range for this example could be A1:B700.

## Set Up An Equation For An Unknown Variable In A Formula Equal To 0

Nov 1, 2008

how to set up an equation for an unknown variable in a formula equal to 0 (an Even-Money Probability Formula for Risk Arbitrage assessments).

The formula is as follows, where I am attempting to solve for Pe:

(Pe*EP)+(P2*EL)=0

Pe=even money probability (placed in column B1 in Excel)
EP=expected profit if deal closes (placed in column B2 in Excel)
P2=probability of deal breaking up (=1-Pe) (placed in column B3 in Excel)
EL=expected loss if deal breaks up (placed in column B4 in Excel)

B1*B2)+(B3*B4)=0

So, once again, I am attempting to solve for Pe, or column B1

B1=(-(1-B1)*B4)/B2

say, EP (or B2) =\$2.00 and EL (or B4)=-\$4.00

B1=(-(1-B1)*-4)/2

B1=2*(1-B1)

## Make Variable Equal To Active Range In Sheet

Apr 2, 2014

I would like to run a calculation based on selected active range in sheet. I tried several methods and cannot make it work.

## Declaring Variable In Sub Statement?

Nov 23, 2011

I am trying to make sense of quite an elaborate macro built by someone else. This has the following line of code

Code:

Dim rowOff As Integer
rowOff = rowNumber - 1
'other arguments and conditions
End Sub

What I am buggered about is that I cannot see the the variable rowNumber being declared anywhere but it seems to have a value of 1. I should mention that Operation is a class and I am very new to classes.

## How To Use Variable In R1C1 Statement

May 29, 2013

I need to know how to use a variable in an R1C1 statement. The statement is as follows:

Set rng = Sheet1.Range("A2:QFinalRowII").CurrentRegion

Ideally the statement would read something like,

Set rng = Sheet1.Range("A2:Q10").CurrentRegion

How would I use a variable name like "FinalRowII" instead of a number?

## Object Name As A Variable In A With Statement

Jan 16, 2007

Does the object in a 'With' have to be an object or can it be a variable containing the name of an object.

I want to carry out the same series of settings on a number of objects
and propose to define a Sub and pass the name of the objects as a parameter.
I then want to use a 'With' to set that object.
i.e. as shown below - though I cant see how it would work.

' combobox objects called Staff, Maker, etc

Call Setuplist("Staff")
Call Setuplist("Maker")
...

Private Sub Setuplist(whatlist As String)
'some complex filtering and sorting goes here
...
Set rnData = ActiveSheet.Range(whatlist+"List")
With Me+whatlist ' this is the bit I cant fathom
.
.
End With
End Sub

## Insert Variable From Sheet Cell Into SQL Statement In VBA Code

Oct 29, 2013

I have the following code to execute a connection to a DB and return the result of the SQL statement. I have a variable in the statement that I want to be able to change from user input in a single cell. Unfortunately I am unable to get this to work.

Here is my code

cell_value = Sheets("some sheet").Range("P8")
Application.ScreenUpdating = False
Sheets("some sheet").Cells.Clear

[Code] ........

This fails and gives me a debug error, however if I declare the condition I want the code executes fine. This would mean having to update the code every time the condition changed or putting the whole query in a cell on the sheet which I do not want to do.

## Values Which Are Equal Not Treated Equal

Jul 5, 2007

I'm having trouble with a small vba macro. At the end of the macro I test to see if two variables are equal and then print out true or false. However, for some reason even though the variables are equal vba is not treating them that way. I have put the values that represent the variables on a spreadsheet and used the if(x1=x2) formula and it says it is true, also, when I debug the macro and watch the values when it comes to test the logical expression the numbers are the same. I don't understand why vba does not say that the two variables are equal. I have attached a screenshot of the breakpoint where I double check the values are equal.

## Hash Marks

May 30, 2007

I have my columns set at a certain width, the cells set to Wrap Text, the Row set to Autofit YET sometimes when I add text, the hashmarks show up as if the cell isnt formatted correctly and Excel cant show all the text. I can resize the cell, change the text whatever, nothing changes. The only way I can fix this is to cut the text out, open a separate worksheet, paste the text into a cell and copy the whole cell BACK into the original spreadsheet, then I have to reformat the text, whereupon it behaves as it is supposed to.

I read about a similiar problem and the reply was that a macro might be causing the error. This is not the case here. This doesnt happen with any regularity so it is very difficult to figure out.

## Getting Rid Of Tick Marks

Nov 28, 2008

Some sent me a large spreadsheet with random rows throughout the spreadsheet highlighted in diffierent colors. I have a module that will sort the spread sheet by Color - however it doesn't work on this spreadsheet because - for whatever reason - every cell starts with a tick mark.

I tried to do a replace all - and excel just told me I was crazy.

I even tried going through and manually removing the tick marks - still no luck.

If I export the sheet in to txt and then re-import it I will loose all the highlights...

## Formula To Consolidate Marks

May 22, 2012

I have three worksheets in which the marks are entered.Now i want to consolidate the marks like

1 in sheet1 2 in sheet2 3 in sheet3 now i want to omit the min(1) marks and add/average of remaining two((2+3)/2)*100.

Is there any formula for this!

## Function To Convert Marks Into Grade

Nov 15, 2013

I am looking for a function that would convert any mark into a grade. For example in cell B4 I want to enter the total score, cell c4 the score that a student gets and in cell d4 the grade. It is like a grade calculator. I do not want to limit cell b4 the total score cell with a specific total score number. It can be 100, 50, 30 or 10. The moment I enter any total score and the mark that a student actually scored, the grade is given. I attached an excel sheet.