Assign Multiple Variables
Feb 16, 2007It's possible to declare multiple variables on a single line as such:
Dim x, y, z As Integer
Is it possible to assign these variables on a single line instead of:
x = 1
y = 2
z = 3
It's possible to declare multiple variables on a single line as such:
Dim x, y, z As Integer
Is it possible to assign these variables on a single line instead of:
x = 1
y = 2
z = 3
I want to assign a cell a formula that changes base on variable, example
myVar=3
Cell(1,1).value = "=average(1:{myVar})"
what do i do to make this work instead of {myVar}?
For example, I have the numerical value "400" in R1C2 and that value would be used in the name "D400" which is to be assigned to R1C1:R5C2.
The code I have is:
Range("R" & DRow & "C1:R" & DRow + 4 & "C2") = "D" & Cells(DRow, 2).Value
but is throwing up the error:
"Run-time error '1004':
Method 'Range' of object '_Global' failed
DRow increases dependant on other variable data.
Also, am I right to be using R1C1 instead of A1, or can the same be achieved using A1 references? If so, I think I may not be able to see the wood for the trees.
I have three variables; Independent variables x & y, and dependent variable z. x & y can take the values 1,2,3 and can equal each other z can also take on values 1,2,3 but can never equal x or y. I tried using if/and statements to solve this (see below), but I would have to do it for each case and it exceeds Excels embedded function limit.
=If(and(B7=1,B10=1),riskduniform(E4:E5),if(and(B7=1,B10=2),3,if(and(B7=1,B10=3),2,if(and(B7=2,B10=2),riskduniform(1,3),if(and(B7=2,B10=1),3,if(and(B7=2,B10=1),3,if(and(B7=3,B10=3),riskduniform(1,2),if(and(B7=3,B10=1),2,if(and(B7=3,B10=2),1)))))))))
I have set up a number of arrays e.g. DataSetA (1 to 100), DataSetB (1 to 100) etc.
Is it possible to use a string variable (e.g. DataIndentifier) to identify and assign values to certain arrays.
For example, under certain conditions
DataIdentifier would be set to "DataSetA" and under other conditions
DataIdentifier would be set to "DataSetB".
Having done this, I want to assign values such as DataIdentifier(1) = 3.4 or DataIdentifier (10) = 6.2 etc.
This obviously won't work because DataIdentifier is defined as a string not an array. How do I enable the string DataIdentifier to be used as an identifier for the array I want to assign values to? Therefore if DataIdentifier is set to "DataSetA" then effectively I want something like "DataIdentifier(1) = 3.4" to assign 3.4 to the array DataSetA(1).
I have a need to populate a summary worksheet using two variables to find data in two or more other worksheets.
I find writing out what I want helps some times so let me try it here.
So my variables are:
Product (there are 22 products)
Supply Less than (inset number)
These are the two criteria I want to use to produce a result.
The next issue is I have 300 stores that carry said 22 products. Each store has a unique number 0001, 0002, 0003 etc. So in a separate worksheet I have a list of the store numbers, and then the products. So each product has the store's number to the left in Column A, Column B has the product name, Column C has the quantity on hand.
What i would like to do on the summary page is select the product, and then select the supply less than or equal to 'x' and then have the stores with the selected product less than or equal to x display below.
The last part of this is then to display (data from an other sheet) on the summary page which contains the quantity of the product selected available at the warehouse for that store.
I'm looking to work out an IF statement based on a series of dates entered to give 1 of 3 possable outcomes. Where:
A1: todays date (exmaple =NOW())
B1: due date (exmaple 10/02/09)
C1: completion date (example 12/02/09)
D1: status (overdue, outstanding or completed)
D1: =IF(A1>B1,"overdue",IF(A1<B1,"outstanding",IF(C1<=>A1 & B1,"completed")))
I know the last part is totally wrong (symbols arranged in that manner), but to clarify i would like the date entered in C1 to override the other statements in the fomula to make it read "completed". If no date is entered in C1 then the formula will return either "overdue" or "outstanding" depending on the other dates in A1 and B1.
I'm making a Form with multiple pages and on every page there are atleast 36 Textboxes.
[Amount] [Description] [price]
I want to run a small sub updating the price on changing the amount. My code now looks like this:
Code:
Private Sub TextBox1_Change()
Call UpdatePrice
End Sub
Private Sub TextBox2_Change()
Call UpdatePrice
End Sub
Private Sub TextBox3_Change()
Call UpdatePrice
End Sub
I have to do this on 8 pages, 24 to 36 times, which makes the code extremely long. Is there a better way to do this?
Something like:
Code:
Private Sub TextBox1_Change(), TextBox2_Change() etc...
Call UpdatePrice
End sub
There are 10 rows of data, and would like to assign value at the end of each row as "initiated" "In the process" "Needs to be Reviewed" "Completed", by using Buttons with different macros.
View 2 Replies View Relatedi want to know how to assign a macro which will remove and place a number in a certain cell. so if i click and tick the box, then a certain figure will come into a cell(this will be a formulae) and when untick the the number will disappear.
View 4 Replies View RelatedNeed exact VBA code syntax to assign a workbook (to be closed) sheet's cells J4 to J72 values to a variable called "ColJValues" to be assigned to another sheet (to be opened later in the macro). The values are all dates. Once the other workbook is opened later in the macro, need the exact syntax to assign the value in the above variable, "ColJValues", to it's cells J4 to J72.
View 8 Replies View RelatedI have over 100 checkboxs on an excel sheet. This sheet will be duplicated 25 times in this workbook.
How can I move this code so its not on each sheet.
Private Sub Aerial_Click()
UG = False
Apartment = False
Range("L68") = "Aerial"
End Sub
I'm looking to find a formula to calculate the red cell (actually all the cells in the "type" fields) by determining:
1) If the Product in the table matches the one in row 3
2) If the dates in table columns H, J, L, N and P took place in the month before the billing date
3) If those two conditions are met, sum the matching columns in I, K, M, O and Q.
For example for the red cell would currently equal $11,380.02 as the only revenue collection dates in range would be cells I1 through I3.
Can I put two variables into a SumIF? forexample I want to sum Column C if Column A is equal to Apples and Column B is equal to Oranges, then sum Column C. Is there a quick formula?
View 3 Replies View RelatedI am looking for a syntax to ask a question with three variables
As an example
If
Blade size = 114 (only 3 blade size choices)
and
the Panel Size is between 500 and 700 ( This will also be dependant on the blade size)
and
the tilt bar is clearview (Three choices)
then
the result will be x = 182
The answers will depend on the above variables: 154, 159, 179, 177, 182 and 202
Screenshot 2014-06-26 14.21.41.png
Screenshot 2014-06-26 14.23.53.png
Screenshot 2014-06-26 14.26.11.png
I need to count up the scores from a questionnaire I have developed, which I am having trouble coming up with a formula for.
I have 5 different types of sales channels in column A. In columns C, E and G there is the call method they use (inbound, outbound or both) with a 'Y' / 'N' option next to it. Basically, I need a formula that if a sales channel has a Y next to Inbound, then the value 'Inbound' to be returned to the destination sale and if it has a Y next to Outbound then the value 'Outbound' returned to the destination cell and so on.
I have attached a spreadsheet to make my problem easier to understand.
I'm trying to use two variable to calculate a count.
In my attachment I have Name, Balance, and Disabled for the data.
I would like to find out how many names has a negative balance and have a "Yes" for Disabled
In the Summary part, I can find out the count of who is disabled, but can incorporate the negative balance.
This code is functional but very redundant and I figured that has to be an easier way to go about this.
View 5 Replies View RelatedI have in cell c40 a data validation list with source equal Royal (=Royal) has been created.
Royal is a namebox that has a defined list of 7 options (6 actual options plus one that says "select via drop down") :
FA4 = Select via Drop Down
FA5 = option 1
FA6 = option 2
FA7 = option 3
FA8 = option 4
FA9 = option 5
FA10 = option 6..............
The concept is that FA5 is associated with a value defined in FB5, FA6 is associated with FB6, so on
What I want to happen is when I select a value via the drop down selection in C40 eg. "Option 1" that in cell D40 the value associated with Option 1 (found in FA5) returns the value found in FB5 ($10).
How do I do this? I have tried a number of "if" statements but no luck.
I'm trying to count a range but I have multiple criteria which I would like to use, I have attempted to use countif/sumproduct with no avail. The data is spread over two columns, one contains the rank of various employees and the other is the number of hours they have worked. I am trying to count how many employees fall in to set hour ranges.
View 2 Replies View RelatedWriting a formula for the info below. Here is what I need basically. If B2>2, then I need it to count all central and field, STK and NSTK in column D.
location
days
stock type
Central
3
nstk
field
1
stk
[Code] ...........
I trying to figure out how to calculate a field based off multiple variables that are dependent on another cell range.
I'm looking to count everything in the C8:C49 cell range that contains either "BETA" or "FINAL" in the cell but ONLY if the F8:F49 cell range contains "In Test")
I am trying to create a column chart in which i want to incorporate 2 variables. However I don't want to use the line for the second variable. What I would like to do is to add the information of the number of deals a company has done on top of the column. So you see a column which gives you the average size of a deal, and the you should see a number at that column to see the number of deals done with that company.
To make this more clear I have attached an example. There are 2 tables of which the information I would like to see in one chart.
I am trying to run the same test on multiple cells, to get the column letters of cells while there are less than 78 columns in use (these column letters will later be used for the Range().Select work involving copy & paste-ing into a word document). I originally thought I could use GoTo statements in conjunction with variables but, having researched it and coming across this, I think I need to find another approach.
At present I have a long section of code that looks like this (I am writing and testing at present so what i make will be put into a larger macro):
VB:
Sub FindColumnLetters()
Dim i01Feb As String, i02March As String, i03April As String
Dim NumbTemp As Integer, NumbTemp2 As Integer
[Code]....
However VBA didn't like the use of variables with the GoTo function and there are not decent ways around. how I can do the original but in less space? FYI the codes above are repeated for 3 columns, where I am actually doing this for ~20 column refs so the space it takes is HUGE at present.
Is it possible to find the formula of a result that is based on three other values.
Here's my example:
I give three cases, but I am sure all three use the same formula. I made the team names up but the values are 'real'.
MATCHES
TEAM NAME
TEAM RATING
OPP. RATING
POINTS DIFF.
NEW RATING
Match1
Blumps
-2.62
5.05
8
-1.28
Match2
Champs
2.8
4.08
-18
2.37
Match3
Sharps
8.26
-3.53
-16
3.68
I want to know what formula was used to calculate the New Rating in the last column. I am not 100% sure if the formula to calculate the New Ratings as shown above includes a value for home ground advantage of which I might be unaware. For what its worth, the Blumps and Sharps were home teams and the Champs was a visiting team for the three matches shown.
Maximum value based on multiple variables. Basically what I have is something like this:
View 3 Replies View RelatedI am working on a survey analysis and I'm having trouble comparing two columns.
Ex. 100 surveys
Column A being age (scale of 1-5)
Column B being willingness to pay (scale 1-5)
I am trying to correlate age with willingness to pay by saying =countif(a1:100 = "1" and (B1:B100 = "1" and "2"))
Basically checking to see if the 1st age group has a strong willingness to pay; I would repeat with B1:B100 = "4" and "5".
Is it possible to modify the sub "Continue" below so that the "If s.Name <> wsKeep" line compares multiple variables? The code is for the purpose of setting a workbook to a required state, i.e. hide all worksheets except ones stated in variables. I have further subs that would also benefit from me knowing how to do this.
View 2 Replies View RelatedI'm trying to create a worksheet to calculate ourcommsiion structure, but can't figure out a way to attack it. We have manyvariables (5) in our commission structure based on each order.
Here's how I set it up so far:
(In Cloumns)
A= Order Amount
B= "Y" is A-15%; "N"=A
C= "Y" is B*20%; "N" is B*10%
D= "Y" is B+2%; "N" is B
E= "Y" is B+2%; "N" is B
F="Y" is B+1%; "N" is B
G= SUM(A:F)
For example, if the order is $1000, and I answer y,y,y,y,y=$212.5
How do I create the formulas so I can just put in the order amount and the
appropriate letter to get the correct commission structure?
I am very new at in depth excel formulas, usually in my daily work I can get by with simple summations, if statements etc. This one has thrown me for a loop.
I'm making a spreadsheet on soil compressibility and I feel like I am just knocking my head against the wall. Here is what I am working with. I need to calculate values in a column, we'll call them "Rm" values.
There are a few basic things that dictate which "Rm" equation you use. I'm substituting V,W,X,Y,Z in for the equations to simplify the question.
I = 3 Rm= W*log(K)
.6