If, Then Inside A For, Next Statement
Oct 8, 2007
I have the below code working but not doing everything that I expect. It counts the number of columns on one sheet and copies the headings to rows to another sheet. One thing is that sometimes there are more than 10 headings and there are only room for 10 rows. So after 10 I need to insert rows. Currently the below code counts and inserts rows correctly but for some strange reason it only copies headings to rows for the first 9.
View 11 Replies
ADVERTISEMENT
Mar 8, 2007
I have a list of parts that I have to create in a system. It is easier to do if I create a list of materials ahead of time of what components are needed. What I have done is create a part list that contains a list of parts, what the cost, whether they are manufactured or purchased, and what the sub component is if they are manufactured.
This worked great till I ran into my first sub component that contain its own sub components. I am attaching the spreadsheet so everyone can see what I am doing or more to the point trying to do. IF VBA is a better solution that would be great.
What I need is a formula (or VBA if it is better) that brings back the sub-components and their sub-components for each part until the parts tree for the original part number reaches the base purchased sub-parts.
I have the 1st worksheet set up in three different ways. The first one you run into is simply a length calculator and can be ignored.
The second way is the original way I had the spreadsheet working and it works fine for parts with only one sub-component. If a sub-part has more than one sub-component then it doesn't work.
The third section is where I started building what I thought would work, but it is clumsy and only will work nicely if I can place an IF statement that will only bring back a value for a sub-component if one exists otherwise it will remain blank.
What I would like is to have a formula that will auto fill the information IF and only if it exists for each sub-part listing all sub-components ( I need if it exists, cost, whether it is manufactured or purchased, any and all sub-components [followed by the same information as the parent] and vendor).
View 9 Replies
View Related
Jun 13, 2009
If A1 shows 10:00am and A2 shows 4:00pm, then A3 calculates the total number of hours: =(A2-A1)*24
But if A1 shows "Off," then A3 shows 0: =IF(A1="Off",0,(A2-A1)*24)
Now, if I want to change "(A2-A1)*24" to another if-statement, how do I do this? I can always set up a hidden cell (A4) that contains the results of the first if-statement, and then say: =IF(A1="Off",0,A4). But can I do this without going through all the trouble of setting up hidden cells?
View 3 Replies
View Related
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
Oct 1, 2008
I'm trying to set up an if statement that will recognize that if a cell is FHR it will do something...but if it's PHR it will do something else. I think I found the place where I keep getting an error but I'm not sure how to go about fixing the issue.
View 2 Replies
View Related
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
May 5, 2014
I have an Excel Sheet which I use as Database. The database has 11 columns and I insert data with the following function:
Code:
Sub testInsert()
Dim adoCommand As New ADODB.Command
Dim sQuery As String
Dim i As Integer
Dim strTest As String
strTest = "test"
[Code] .......
Now I want to retrieve this data. i.e. I want all F1 where F2 and F3 are 0 AND I want them ordered descending. I'm trying to achieve this with:
Code:
Sub testSelect()
Dim adoCommand As New ADODB.Command
Dim sQuery As String
Dim mrs As New ADODB.Recordset
Dim strTest As String
strTest = "test"
[Code] ....
The result I am getting looks like this:
9
8
7
6
5
4
3
2
15
14
13
12
11
10
1
I assume, that the data is interpreted as String instead of an integer. But I explicitely stated the data as Integer when storing the data into the DB.
View 5 Replies
View Related
Nov 12, 2008
=BDP("067901108 cn corp cusip","px_last")
is there a way to insert 067901108 cn corp cusip from a different cell into the formula?
067901108 cn corp cusip <---A1
067901108 us corp cusip <---A2
something like this?
=BDP("A1","px_last") which equal to =BDP("067901108 cn corp cusip","px_last")
=BDP("A2","px_last") which equal to =BDP("067901108 us corp cusip","px_last")
View 2 Replies
View Related
Jun 9, 2009
DISCUSSION:
I have some general code that needs to be kept tidy so I have been experimenting with calling other Modules to keep that general code short and sweet.
PROBLEM:
How to put the SUB's inside of another SUB on a separate Module?
Here is the desired pertinent code on the general code sheet:
View 7 Replies
View Related
Dec 16, 2011
I have a userform that updates col's A thru E. (undetermined amount of rows)
I need to sum col's B thru E individually.
It would always be summing from row 3 of col B thru E.
I have the code that finds or selects the last cell of each col.
I'm not sure how to put the "countif" function code into VBA.
Example would be col B would be populated with the letter "A".
I would need to count how many "A's" in column B.
View 2 Replies
View Related
Jan 20, 2012
Okay, I know you can reference worksheet functions with code like:
application.search()
But how do you use a UDF function within VBA???
I tried, thisworkbook.UDF() (UDF being the name of any UDF) but it didn't work.
View 3 Replies
View Related
Apr 8, 2009
I have a table of values that are computed using input values from the first column (y's) and first row (x's). Each value in the table (z's) has a unique set of x and y.
In order to plot z vs x and z vs y I need to create a list of unique x,z and another of y,z. My question is how most efficiently to thus turn this table "inside out." The table will be very large, or I would do it by hand.
View 9 Replies
View Related
Jun 21, 2014
I have an excel work book that I want to extract certain info from Each tab where in the result tab I use this formula to get required data from another tab.
I has about 24 tab , in the 25th one i collect data from all previous , using below formula inside each cell to get
=INDEX('2014 wk12'!$C$1:$C$17,MATCH("Total LTD Result",'2014 wk12'!$A$1:$A$17,0))
Where 2014 wk12 is a tab name , so , it works fine
excel iss.png
What i want is t replace the sheet name which in previous example is 2014 wk12 with relative name in column A
The closest i have in mind is to make it as below ( it is not working ) so what shall be the working formula of the below
=INDEX('Tab name from Column A '!$C$1:$C$17,MATCH("Total LTD Result",'Tab name from Column A'!$A$1:$A$17,0))
View 6 Replies
View Related
Jul 9, 2014
So I have a formula which contains a countifs that looks like this:
=COUNTIFS($AZ:$AZ,$AZ15,$AM:$AM,ABS($AM15),$AD:$AD,$AD15)
However, I want the formula to count values when ABS($AM:$AM)=ABS($AM15) but I get an error if I try to put ABS($AM:$AM) as my range. Is there anyway to set my range as the absolute value of Column?
I have also tried ABS($AM15:$AM1000).
View 10 Replies
View Related
Nov 21, 2008
I have this: =LOOKUP(Budget!J3,B11:B42,E11:E42) RESULT: 5%. what I want: =LOOKUP(Budget!J3,B11:B42,(X3)11:E42) RESULT: 5%. I want excel GET the value inside X3 and and go to the other sheet with this variable. X3 = E
View 2 Replies
View Related
Feb 8, 2010
I'm trying to calc a Simple Moving Average of financial Fund data (row=fund type, column=date) on a very large matrix for a particular fund and date range. I locate the Fund of interest and retrieve the Start and End dates of interest and retrieve their addresses using the ADDRESS function. Since ADDRESS returns a text string, HOW DO I incorporate it's results into the following array function (which ignors blanks and 0 cells): {=AVERAGE(IF($L$10:$V$10>0,$L$10:$V$10,FALSE))}?
View 5 Replies
View Related
Feb 17, 2014
I am trying to create a For Loop where the RND from array column sptemp(i,2) is static throughout the entire loop when I pull the data out separately by columns to create a chart. The data works perfectly if I print it out on the excel spreadsheet via ctrl+shift+enter as an entire array but I am trying to graph the columns and the RND is updating and not syncing with the same random number, as sptemp(i,3) and sptemp(i,5) are both linked to sptemp(i,2) which is the RND. I am trying to graph column 3-5 on the Y-axis and column 1 on the X-axis, and column 3 and 5 should look identical after subtracting column 4.
View 1 Replies
View Related
Feb 27, 2009
I'm trying to get dropdown in cell. Depending on what is chosen, I then want another dropdown in the same cell of either New or Old for the item previously chosen. Hopefully the example helps because even I'm confused by this.
View 6 Replies
View Related
Nov 13, 2008
Is it possible to make a function inside a textstring?
E.g. - The area of the building is [=A1] mē and contains [=A2] apartments.
View 3 Replies
View Related
Nov 15, 2011
I have a string like this ('hello'). How can i get the string inside the quotes ie hello?
View 2 Replies
View Related
Aug 2, 2012
I am wondering if you can write me a VBA code for comparing the value inside a cell.
Code:
For i = 1 To 159
If Sheets("sheet1").Cells(i, 1).Value = Sheets("sheet2").Cells(i, 1) then
..............
Else
[Code]....
View 9 Replies
View Related
Mar 30, 2013
how can I use a formula via VBA instead of putting it in the cell itself? It is causing me problems because when I put a formula in a entire row, all the cells five me the number ZERO, when I want them to stay without any number until I input something in the other row's cell in the same line. I will give an example: I would like that anytime I entry any number in a cell in column A the cell in column C will give me the number in column A times the number in column B (which is a variable daily updated via an internet connection), and when the cell in column A becomes "null" (that is when there is no number in the cell, not even a zero) the cell in column C also becomes null.
When I try to do it using formulas in the cells I always get a ZERO in all the column cause they read a 'null' as a 'zero'. Trying it using VBA I have some success but still have problems. I tried this code
If Target.Column = 3 Then Cells(Target.Row, 8) = Cells(Target.Row, 3) * Worksheets("Sheet4").Range("d32").Value
But it makes the cell in column 8 be static and change only when I click on the cell in column 3. I need it to change automatically when the number in D32 is changed too. As a formula in the cell would do.
is there any way to input a formula via VBA, how?
View 4 Replies
View Related
Jan 5, 2008
Sub Macro1()
Sheets("AllSheets").Select
Charts.Add
ActiveChart.ChartType = xlLineMarkers
ActiveChart.SetSourceData Source:=Sheets("sheet2").Rows("48:48")
ActiveChart.Location Where:=xlLocationAsObject, Name:="sheet2"
ActiveSheet.Shapes("Chart 7").ScaleWidth 1.79, msoFalse, _
msoScaleFromBottomRight
ActiveSheet.Shapes("Chart 7").ScaleHeight 1.01, msoFalse, msoScaleFromTopLeft
ActiveSheet.Shapes("Chart 7").ScaleWidth 1.09, msoFalse, msoScaleFromTopLeft
ActiveSheet.Shapes("Chart 7").ScaleHeight 1.01, msoFalse, msoScaleFromTopLeft
End Sub
i need the chart to be inside allsheets. currently it create a new sheets chart1 once i generate it.
View 9 Replies
View Related
Mar 8, 2007
=StacServer|Windham! '40720'
This is the format of an external call that I am trying to run. I need to change the number (40720) based on the day of the month (i.e. if its the 5th, then use 40725.
I am attemting to use a function to do this and passing in the device name (Windham) and location (40720). Unfortunately, I have been unable to get a String to send back as a formula. My attempt was as follows :
= Location ("Windham", 40720, "D7")
Function Location(name, num, cell)
Dim psDay As Integer
Dim psLocal As String
psDay = Day(Now)
Location = (Range(cell).Formula = "=StacServer|" & name & "!'" & (num + psDay) & "'")
End Function
View 9 Replies
View Related
Dec 3, 2007
When I use TextBox.SetFocus in a userform , the curser will be inside the TextBox,
My TesxtBox has a value in it, so when i apply the TextBox.SetFocus I want the value to be highlighted insted of only being the active TesxBox.
View 4 Replies
View Related
Feb 22, 2013
I tried to count rows from one sheet and to put this value as counter in VBA For-Next loop.
VB:
Sub Copy_ID()
'
' Copy_ID Macro
[Code]...
It ends with "Invalid qualifier" error on the counter.Formula line. I attached sample excel with macro that I listed here.
View 5 Replies
View Related
Aug 28, 2013
Sometimes when i run code under a command button on a pop-up user form, the contents of the userform go "blank (i.e., border stays on, so you can see that the form is still there, but the contents are all "white"-you cannot read/see any of the content...
What could be done to prevent this from happening (presently, i just have the mouse cursor displaying while code is running?
View 4 Replies
View Related
Jun 21, 2014
I have a challenge with conditional formatting. I have products A-K with sales current year and last year and want to have year on year growth. I want to have one column where the cell formatting changes based on data validation.
Let's say product A sold 60 items CY and 50 LY meaning YoY variance is +10 items or +20%. Hence, if the relevant cell says "%" then the YoY figure should say "+20%" (formatted as a percentage) and if "VALUES" then YoY should be 10 (formatted as numbers/absolute values).
Remember also that YoY growth can be +100% (or more), 0% and -100%.
View 10 Replies
View Related
Oct 6, 2013
Is there a particular function which will allow me to count particular names inside cells, e.g, in cell A1 there are three names(Ben, Jack, Tom), cell B1 (Jane, Tom, Andy). I'm looking for a formula which will count the number of occurrences of Tom in cells A1 and B1.
View 3 Replies
View Related
Jan 7, 2014
I have the following formula that has ceased to work in excel. I don't think there are any errors in it so I'm unsure as to why the link no longer works. Neither of the files I'm using has moved location on the server.
=IF(H7>0,(I7*H7)+((I7*H7/100)*VLOOKUP(B7,'T:FILEFILEFILE'!$B:$E,4,FALSE))+0.25,0)
I'm not sure if this makes much of a difference but people opening the file use various versions of Microsoft Office.
View 10 Replies
View Related