Excel 2010 :: ElseIf And Or Statement In VBA

Jun 27, 2013

I have tried to shorten my code by combining common tasks, however it runs but selects the wrong data. In the example below,

The code returns the expected if I select "M135X" and "300 hrs", but unexpected results if "M135X" and "1500 hrs" is selected

My variables are models and hours - the code below is for one model.

Code:
'Next Model
ElseIf Range("D3") = "M135X" And Range("E3") = "1st Service" Then
ThisWorkbook.Worksheets("M100X-135X").Range("B37:D44").Copy
Range("J10").Select
Selection.PasteSpecial Paste:=xlPasteValues
Application.CutCopyMode = False

[Code] .........

View 5 Replies


ADVERTISEMENT

Elseif Statement Find Next Empty Row

Jun 19, 2006

I have created a user form with a combo box and three text boxes. The drop down box is populated via the initialization of the form; code is posted below.

the "add item" names are names that are already on the worksheet in column 1. What i have done is used the command button "submit" to populate the information from the textboxes to the worksheet.

what i would ike to do is populate the empty cells below this area with the information that is in all three text boxes and the combo box. for the IF / elseif statments i have used the combo box as the condition. So the quandry is I cant input the information into the empty cells, i have tried a few things, my vba is very basic, as you can tell ihavent even DIM'd anything (i think that is another thread though :D )

here is the initialize code and below is the "submit button" code.


Private Sub UserForm_Initialize()
'sets values for text boxes
cbomaterialdiscription.Value = ""..........

View 9 Replies View Related

Excel 2010 :: Use One Set Statement To Set Second Statement?

Feb 14, 2012

I am attempting to use a previously Set variable as part of the next Set statement, pretty unsuccessfully at present.

My purpose is trying to look up

Code:
tb_SelJobID.Value

from a userform in Col Z then look across the row to Cols D,I,N,S & W (different types of work) to see if

Code:
TbSelYr.Value

matches the year selected then insert a formula in the row to the left. Then loop down to the FinalRow.

Currently my Set Found1 statement does not recognise my Found10 value. I know it will be my syntax as it always is. I have cut down the following code to display where the problem areas are, Found1 thru 5.

Code:

Sub CmdGo3_Click()
Dim Row As Range
Dim FinalRow As Long
Dim Found1, Found2, Found3, Found4, Found5, Found10 As Range
Application.ScreenUpdating = False

[code]....

Windows 7 with Excel 2010

View 9 Replies View Related

Elseif Statement In Vba: If The Selected Cell Falls Between 1/01/06 And 31/01/06 Then Jan Would Be Selected

Oct 10, 2006

Basically it is a if statement saying that if the selected cell falls between 1/01/06 and 31/01/06 then Jan would be selected. The end part is not a problem; I’m just not sure how to write the one line of code that would test if the cell falls between the two dates. I attemped to create it as shown in the code attached below but wasn't successful. I used an else if statement to test the other 11 months.

Sub test()
Dim SelectDate As Range
Set SelectDate = Range("SelectedDate")
If selectedDate >= 1 / 1 / 2006 And selectedDate <= 31 / 1 / 2006 Then
ActiveSheet. PivotTables("PivotTable1").PivotFields("PnLDate").CurrentPage = _
"Jan"
ElseIf selectedDate >= 1 / 2 / 2006 And selectedDate <= 28 / 2 / 2006 Then

ActiveSheet.PivotTables("PivotTable1").PivotFields("PnLDate").CurrentPage = _
"Feb"........................

View 4 Replies View Related

Excel 2010 :: Condensing Dim Statement

May 7, 2013

Windows 8, Excel 2010,

What is a condensed way of saying;

Dim x As Integer
Dim y As Integer
Dim z1 As Integer
Dim z2 As Integer
Dim z3 As Integer
Dim z4 As Integer
Dim AA As Integer

View 9 Replies View Related

Excel 2010 :: Change Color On If And Then Statement

Nov 20, 2013

I tried Conditional format and no luck. (Office 2010)

What I'm trying to do VB is:

If Cell B:B has value of "402" or "up"
and Cell C:C is less >100
Then Change color on Cell C:C to "yello, red, etc" (if C value is <100 no color change)

View 6 Replies View Related

Excel 2010 :: Runtime Error When Using Like In SQL Statement

Feb 5, 2014

Excel 2010. Windows 7

Run-time error '-2147467259 (80004005)':
An unexpected token ""20*"" was found following "1' AND
PERIOD = LIKE*. Expected tokens may include: "". SQLSTATE=42601
code died at RS.Open SQL, CN
/////////////////////////////////////////////////////////
Sub GET_OSI
Dim sn as String, osi as string, saposi As String

[code]....

View 2 Replies View Related

Excel 2010 :: Determine Row To Calculate Based On Statement

Jul 5, 2014

I need some different columns within a row to calculate based on a statement found in an earlier column in the row. something similar to below. there will only be two statements total which are noted on the table below.

A
B
C
D
E

1
0
0
20
5%

[Code].....

So basically If column A = disposition calculate D and E in column B but if Column A = Receipt calculate in column C

The formula for D and E is not exactly as shown just using that as a quick example. I'm using office 2010.

View 1 Replies View Related

Excel 2010 :: Change Several Cells If Statement Is True?

Oct 11, 2013

I am using MS Excel 2010 want what to change a number of cells if a value is true e.g.

Row one has the headings Prz, Stat, Val, andPts
Row two has the following values :-
(Prz) a2 =2, (Stat) b2=1, (Val) c2=$30, (Pts) d2=10
How do I do the following in Excel :-
IF B2=1 THEN A2+1 AND C2+30 AND D2+5
so that the above cells are changed to
(Prz) a2 =3, (Val) c2=$30, (Pts) d2=10

View 4 Replies View Related

Excel 2010 :: Execute Statement ONLY When Macro Run From Button

Aug 27, 2012

1) I have a VBA macro MyMacro() which works fine.

The macro is assigned to a button on the w/s, and also runs from w/b Open() event and other locations within the w/b.

2) The macro displays a message just before exiting whenever it is called.

3) I’d like the MsgBox statement in the macro to be executed ONLY when the macro is run from the button.

In other words, skip the MsgBox statement when the macro is run from anywhere else in the VBAProject.

Can this be done ? possibly by inserting a statement or two before MsgBox in the MyMacro() code ?

View 4 Replies View Related

Excel 2010 :: Hyperlink With IF Statement - Cannot Open Specified File

Aug 30, 2012

I Have a CheckBox Thats Linked with CA22

In Cell CB22 I have the Following Formula:

=IF(CA22=TRUE,"1","")

In Cell CC22 I Have...

=IF(CB22="1","RM-4E ADD1",HYPERLINK('RM-4E (Add - 1) (2)'!A1,"RM-4E ADD1"))

The Sheet namne its supposed to Hyperlink to is called

RM-4E (Add - 1) (2)

When the Check Box is Unchecked it Changes CA22 to False and Puts in CC22 Text: RM-4E ADD1

When the Check Box is Checked it CHanges CA22 to TRUE and is supposed to create a Hyperlink to that sheet...Only when i click it it comes back with

'Cannot open the specified file."

I even went as far as typing out the Word Hyperlink( clicked the sheet and selected Cell A1 on that sheet but it still comes back with the error!

Excel 2010

View 9 Replies View Related

Excel 2010 :: Pivot Table For Financial Statement With Months As Columns

Jul 4, 2012

Excel 2010. I set up a trial balance as following:

1/31/2000 2/28/2000 3/31/2000 ------- 12/31/2012
Acct # 1
Acct # 2
Acct # 3
Acct # 4

I was able to use pivot table to set up the balance sheet and income statement.

1. now each month is a field which I can choose to add to the report, but the field list is getting too long (and growing). Is there a way I can insert 1 field (for the user to input the exact date) or 2 fields (to input year and month) and the pivot table can pick up the input and refresh either automatically or manually.

2. I looked into the "group" function in pivot table, but how do I group the above data in quarterly and yearly fashion so the user can get those information quickly?

View 1 Replies View Related

Excel 2010 :: If Statement With Text As Range Of Values And Numbers Needed As Output?

Apr 23, 2013

Excel 2010, I have the following list (showing part of it):

Name
T-Shirt Sizes
Nathan
S

[Code]....

The aim of the list is to see what Sizes each and every person needs and then count how many T-Shirts are required for that particular size. The list is over a 100 entries long so counting it manually isn't really an option as it's time consuming as well as errors might arise.

Thus, I've been trying to use the IF statement with the following logic but to as no avail

IF Size in Column is XS
Add 1 to a particular Cell
IF Size in Colum is S
Add 1 to a particular Different Cell

and so on for the other sizes...kind of like a counter for a for-do-loop.

View 2 Replies View Related

Excel 2010 :: Summary All Statement From 4 Worksheets And To Summary All Total ICC

Dec 23, 2013

excel 2010. This workbook has 4 worksheet(Process Engineer,OSBL,OSA,Lab Operator) I want to know what is the best excel formula/function to summary this 4 worksheet.

Example:I want a formula/function to summary all the statement from 4 worksheets and total number of answer "1" per statement from 4 worksheet.

Sample Statement below

"Demonstrate Interpersonal (People-to-People-) Skills" Question:What is the formula if above statement contains this statement in 4 worksheet?As i checked the total is 4 then What is the formula to get all total answered ICC on this statement from 4 worksheet?

View 2 Replies View Related

VB ... If/ElseIF

Oct 13, 2009

develop a macro to send e-mails upon certain criteria, I then wanted to add a layer to the macro which I have, and it works... sort of. I'm wanting the Macro to send a specific e-mail if the dates fall between a certain range, a different e-mail if they fall between another range, etc... Here is the code I came up with:

Private Sub Workbook_Open()
Dim LR As Long, i As Long, s As String, sb As String, sc As String, eml As String
With Sheets("Vendor-Rltshp")

View 9 Replies View Related

Ordering If, Else, And ElseIf Statements In VBA

Jun 6, 2009

I have an enquiry where I'm trying to order error messages which occurs in if, ElseIf and Else Statements. The code I have works. However, I would like the error messages to be checked in a particular order. I tried rearranging the conditional statements but had no success. Here is my

View 5 Replies View Related

Array- Adding New Elseif's

Jun 6, 2008

I started changing it and then realized that I can keep going by adding new elseif's but i think an array would be a better option(i think). But i am really a monkey see monkey do kind of vba user. i can backwards engineer but cant come up with it.

here is code

Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("$z:$z")) Is Nothing Then
If Target.Value = "NO CONTACT" Then
Target.Offset(0, 1) = Date + 1
ElseIf Target.Value = "NO CNTC FCL" Then
Target.Offset(0, 1) = Date + 1
ElseIf Target.Value = "NO RES" Then
Target.Offset(0, 1) = Date + 1

you see i keep adding "results" and assigning lift dates. what i would idealy want to do is take my list (that i use in a drop down box in $z) and next to it assign the number of days i want to set the next call date(the offset 1 cell) to be. then have the code just read cells a1:a10(the results) and assign the corresponding b1:b2(the amount of days to wait to call). I can keep adding elseif's but then if i decide to add new results codes or change the days from 1 to 5 i have to go back to the code.

View 9 Replies View Related

Starting A If And Elseif String

Apr 13, 2007

In row 6 column O I need for the formula to look at column I and determine if the month is 1, If yes then I need for it to determine if the date is one of the following,

Day(I6)>=1,Day(I6)<=5), If TRUE Then do the following
Cells(J6)*1.04)*2080/12
If False then
ElseIfDay(I6)<=6,Day(I6)=<12, If TRUE Then do the following
Cells(J6)*43.33)+((J6*1.04)*129.99
If False then
ElseIfDay(I6)<=13,Day(I6)=<19, If TRUE Then do the following
Cells(J6)*86.66)+((J6*1.04)*86.66
If False then
ElseIfDay(I6)<=20,Day(I6)=<26, If TRUE Then do the following
Cells(J6)*129.99)+((J6*1.04)*43.33
If False then
ElseIfDay(I6)<=27,Day(I6)=<31, If TRUE Then do the following
Cells(J6)*1.04)*2080/12, but put this into column P

If row 6 Column O if the month is greater then 1 then I need the formula to do the following,
=J6*2080/12

What I am trying to do is have excel take columns O through Z look back to column I and determine which month the performance review is due in. Then I need for it to determine which week the increase rate will be effective for. So for each month the “If the month is >1” would change to 2,3,4,5,…..and so on.

In addition I am going to have the formula look at the shift and if it =3 then (J68)+1.00, but for the increase I have to have it -1.00 then J6*1.04+1.00. I will also have to create a table that holds the max rate for each grade, and then figure out the formula to figure out this new rate.

View 7 Replies View Related

Multiple ElseIf Statements With Areas

Dec 6, 2006

My code is below. See how I have repeated the same code over and over for each row. Is there a shorter way to write this, perhaps a cleaner way. Im not an expert and I write what I know and most of that is long code that can be shortened.

If MyScreen.Area(7, 2, 7, 4) = "102" Then
Workbooks(2).Worksheets(1). Range("B" & row) = "Yes"
ElseIf MyScreen.Area(8, 2, 8, 4) = "102" Then
Workbooks(2).Worksheets(1).Range("B" & row) = "Yes"
ElseIf MyScreen.Area(9, 2, 9, 4) = "102" Then
Workbooks(2).Worksheets(1).Range("B" & row) = "Yes"
ElseIf MyScreen.Area(10, 2, 10, 4) = "102" Then
Workbooks(2).Worksheets(1).Range("B" & row) = "Yes"
ElseIf MyScreen.Area(11, 2, 11, 4) = "102" Then
Workbooks(2).Worksheets(1).Range("B" & row) = "Yes"
ElseIf MyScreen.Area(12, 2, 12, 4) = "102" Then .....................

View 3 Replies View Related

Excel 2010 :: Getting Outlook Warning (2010) While Sending Email Through Macro

Mar 25, 2014

I am trying to send bulk emails from my excel 2010 - however I am getting a POP UP. find the screen shot in the enclosed word document So every time a new mail is sent from excel we need to press the button allow Is there a way where I can turn off this warning.

View 6 Replies View Related

Excel 2010 :: How To Save Excel File As Cell Reference Using Macro

Mar 5, 2012

I have created a macro in excel 2010 which enable the file to save (extract) data into separate location and name. The vba code for macro is as follows: Question: How can I save this workbook with reference to the value containing in cell B2? (it is named temporary now - as defined in the code)

Sub aaa()
'
' aaa Macro
'

[Code].....

View 1 Replies View Related

Excel 2010 :: Macro To Change Excel Formatted Table Name Dependent On Number Of Loops

Jul 9, 2012

Recorded macro. The hope is to insert a excel formatted table a set number of times. I have found a loop code that references a Cell A1 and repeats that amount of times. So if A1= 10. There should be 10 tables inserted. However on the second time there is a fault with the table name. I need the name to change each time the loop is run. ie Table1, Table2, Table3 etc up until the loop stops (A1 contents).

I am using excel for windows 2010. The macro that i have so far is below.

Sub LoopTest()
Dim n
Dim V
Range("A1").Select
V = ActiveCell.Value

[Code] ........

View 1 Replies View Related

Adjust Macro From Excel 2003 To Excel 2010?

Apr 1, 2014

I am trying to adjust the below macro so that it will work in Excel 2010.

Sub OpenAndProcess()
Dim fs As FileSearch
Dim I As Integer

[Code]....

View 3 Replies View Related

Excel Calculation - If Statement That Can Be Used On 2 Columns?

Oct 2, 2013

I need a If statement that can be used on 2 columns.

If there is a 1 in the first column I want to indicate if the 2nd column is 50% or greater with a number 1.

View 3 Replies View Related

Excel 2007 :: Do Loop With IF Statement

Nov 12, 2013

I am having an issue getting an IF statement to work inside a DO loop. I have Microsoft Excel 2007 and Windows 7 Entreprise.

In my Excel spreadsheet, I have in column B a list of keywords and in column C the category to which each keyword belongs. For instance, the keyword "boot" goes withe the category "Shoes", "scarf" goes in "Accessories", etc.

In another column, I have a list of product descriptions (like "Black Boots" or "Silk Scarf") and I would like to assign the relevant category to each product. I thought to do this by creating a new function in VBA. This function would go through the whole list of keywords in column B, checking if the keyword is included in the product description. If it is, the function's result would be the relevant category, and if it is not, the function would search the next line in column B, until a relevant keyword is found, or until the end of the list.

Here is the code I have written so far:

Code:
Function SegmentSearch(Item)
Dim i As Integer
i = 1
Do
i = i + 1

If Application.WorksheetFunction.IsNumber(Application.WorksheetFunction.Search(Sheet5.Cells(i, 2), Item)) = "TRUE" Then SegmentSearch = Cells(i, 3)
Loop Until Application.WorksheetFunction.IsNumber(Application.WorksheetFunction.Search(Sheet5.Cells(i, 2), Item)) = "TRUE"
End Function

Without the loop, the function works fine (if "Item" happens to include the first keyword in the list) but as soon as I try putting the loop I get a #VALUE! error.

View 7 Replies View Related

Excel 2013 :: If Statement To Generate Timestamp?

Feb 20, 2014

I am using Excel 2013 on a windows 8 machine. It may be easier for me to explain the problem, before posting about the formulas. I maintain a retirement residence with alot of phone numbers. I have a list of all the numbers we own in one column and the numbers assigned to the PBX systems in a second column. By using a If formula I can tell which numbers have not been assigned (The true statement). My problem is when a resident passes away, I need to reuse that "phone number", but I dont want to reuse the number too soon. I am hoping to use the "true" from the if statement to generate a time stamp. I plan on using that time stamp against the "today()" in a days formula, I believe this will spit out the number of days a number has been idle. The time stamp would be constantly changing or removed as the if statement would always be changing. So column C gives the True statement and says "Number not Assigned" - this should create a time stamp in Column W

A
B
C

[Code].....

View 4 Replies View Related

Excel Sheet1 Comparing Data - Get Stuck After Second IF Statement

Aug 1, 2013

=IF(M7="","",IF(K8=J8,K8&$J$3&I8,IF(K8=I8,K8&$J$3&H8,IF(K8=H8,K8&$J$3&G8,IF(K8=G8,K8&$J$3&F8,K8&$J$3&J8)))))

I have tried several options, ISERROR(FIND(.................also EXACT(........ and they all seem to get stuck, after the second expression.

Basically, I have a ROW of Cells, with numbers inside them, like so:-

F8.....G8....H8....I8...J8....K8
27.....33....10.....4....4.....4

And looking from right to left, I am asking this question:-

If K8=J8, then I will have K8 & I8 as my result.
If K8=I8, then I will have K8 & H8 as my result.
If K8=H8, then I will have K8 & G8 as my result.
If K8=G8, then I will have K8 & F8 as my final result, Else its K8&J8 as my FALSE.
(the $J$3 = a comma, for number separation, and further LEN string capture.)

Every time I have made this formula, with other types of Logic, it only ever finds the second tier depth as the result,
and I wonder why, since they are several nested IF statements in line!!

The incomplete Excel sheet is attached : S 1_2 tracker Forum.xlsx

The result of the above formula should be 4,10
But instead I get 4,4

View 2 Replies View Related

Excel Hangs And Freezes After Writing Simple If Statement

Nov 3, 2012

Background: The user makes a selection from a drop down box on the main sheet (sheet5, G12). The drop-down box is linked to *Sheet31.Pax_Nav*. If the drop-down box's linked cell value is less than 5, then do nothing (manual input required). If it is greater than 5, then the vlookup matches that number to a person in the database and returns their weight. The code will pull the required person's weight but then Excel will hang and freeze.

Private Sub Worksheet_Calculate()
On Error Resume Next
If Sheet31.Range("Pax_Nav") > 5 Then
Sheet5.Range("G12").Value = Application.WorksheetFunction.VLookup(Sheet31.Range("Pax_Nav").Value, Sheet31.Range("H17:L48"), 5, False)
Else
End If
End Sub

View 9 Replies View Related

Excel 2011 :: Conditional Formatting Based On Text Match From If Statement?

Oct 2, 2013

I want to highlight a cell if the text displayed from an IF formula is equal to the cell content.

CELLS BK10:BN10 are merged and have entered into them the following text "SELL"

Cells BJ20:BP20 are merged and contain the following formula which currently results in the cell displaying "SELL"

=IF(BM22<=-0.08,"SELL", IF(AND(BM22>-0.08,BM22 < -0.03),"NO INDICATION", IF(BM22>=-0.03,"HOLD")))

Cell BM22 is a percentage calculation of the differences between two different days of volume for this stock and that formula is: =(BH22/BH25)-1 Cell BM22 currently is calculating the result to be -65.65%

When I set up a CLASSIC Conditional Formatting using a formula (="If($BJ$20=""SELL""") to check the if the text in cells BK10 match the text displayed in cell BJ20 - I get no error messages and no formatting?

I am using Mac Office Excel 2011. I feel like I have tried everything including changing the Number selection type of the cells to TEXT. Nothing seems to works.

View 1 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







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