# Cell Value Range In Code Formula

Oct 31, 2007
Here is my

Dim value1 As String

value1 = "=OFFSET($B$6,$A6-1,0,1,1)"

Range("g6:ad12").Formula = "=SUMIF(OFFSET(" & value1 & "!$j$6,0,0," & value1 & "!$A$5,1),(" & value1 & "!AS$5)-1,OFFSET(" & value1 & "!$n$5,1,0," & value1 & "!$A$5,1))"

my "value1" needs to equal the value in the corresponding row for the formula. For example:

B6 = "BEA"

B7 = "GE"

B8 = "TAS"

My formula only gets cell B6 value and doesn't pick up B7 or B8 as the formula copies from G6:AD12

how do i get it to pick up B7 then b8?

View 9 Replies
ADVERTISEMENT
Jun 10, 2008

I have a formula that works fine in the cell of an Excel spreadsheet but I'm struggling to translate it into VBA (your help please).

The cell formula is:

=If(B2="", "", B2 & " (version: " & F2 & ")")

I want to iterate through all rows in my spreadsheet (about 2000) incrementing the relevant row numbers in the formula @ each pass - eg changing B2 -> B3 -> B4 etc and F2 -> F3 -> F4 etc where column 'B' contains the name of the product and column 'F' contains the version number, resulting in "Product Name (version: 123)" per row.

The closest I've got to this is:

Sub LookupNameInColumnA()

Range("A2").Select

Dim i As Integer

For i = 1 To Selection. CurrentRegion.Rows.Count - 1

ActiveCell.Formula = "=IF(B2="""", """", B2 & "" Version: 999"")" ' problem line?

ActiveCell.Offset(1, 0).Select

Next i

End Sub

This works OK'ish but I want each line to reflect the different data per row. I'm struggling to increment row 'B' and row 'F' in the formula, having tried "B & i + 1" and "F & i + 1" but am getting confused with quotes and concatenating strings within formulas.

View 5 Replies
View Related
Jun 3, 2014

I am trying to find out how many weeks our current inventory will support our sales. I am trying to research formulas that will do this, and coming back with things like OFFSET, MATCH, INDEX but am not certain the best way to put them together to get what I need. I use excel daily, but this is a bit mroe advanced than I am used to

Mini.xlsx

Starting in cell B4, I would like to count how many weeks of Demand can be covered by the specific Available On Hands in row 3 for that week, put the number of "Weeks Covered" into cell B2, and then fill over to the right in row 2. Right now, the values in row 2 are from my own manual calculations, but I would like a dynamic formula that will sum up the values in row 4 up to (but not greater than) the value in B3, give the count of cells that reached that sum (or even better with decimals to show the percentage covered), which I will copy over into B3:B13. Not sure if that makes sense, or if I can explain in a better way. The yellow cells are what I am trying to create a formula for and am currently stuck.

View 6 Replies
View Related
Apr 28, 2008

I have workbook template that I use to generate reports from a list of depts. This list is contained in a drop down cell that is a named range in a different worksheet. My current process is as follows:

-Select Dept Name from the list

-Click a command button which is assigned to code that calculates and saves to a file

-Repeat for next report until all reports are generated

I would like to automate this process by producing all reports with a single command with the following functionality:

-The Dept Name needs to be populated in the specified cell containing the current drop down because it drive various vlookups and other formulas

-If possible, I would like to retain the drop down functionality as I would like to have the option of running an individual report or running the batch.

View 2 Replies
View Related
Aug 16, 2007

I tried putting a formula into the below code but without any success.

mylogoff. Offset(0, 3).FormulaR1C1 = "=IF(WEEKDAY(RC[-1]=""6"",""17:30:00""+0,""18:00:00""+0)

It says application defined or object defined error.

View 5 Replies
View Related
Sep 30, 2006

I am using the Networkdays function to calculate the number of working days between a date entered in A1 and a date in B2 and I have a range of holidays called 'holidays' and then have the result placed in E1.

View 9 Replies
View Related
Dec 17, 2008

Does the line of code assign the value of cell A5 to the range or is it just a startinig point?

View 9 Replies
View Related
Jul 16, 2009

I have a function that is called upon saving a UserForm. One of the Text Labels contains the ID field that I need to use to do a lookup into the first column of a Named Range and then I need to update the cell in the 4th column of that row.

From my research, I'm assuming it will go something like this:

Application.WorksheetFunction.VLookup(valve, Worksheets("TestWorksheet").Range("TestRange".Cells), 10, False).Value = "TestValue"

View 9 Replies
View Related
Aug 14, 2008

I try to put a formula to a certain cell using this code, but I get application defined or object defined error:

HTML Selection.Cells(1).Offset(0, 5).Formula = "=INDEX(range1;MATCH(""D""&C13;range2;0);MATCH(""S""&D13;range3;0))"

The weird thing is, that if I type the same formula itself to a cell, it works, so the problem shouldn't be with the formula:

HTML =INDEX(range1;MATCH("D"&C13;range2;0);MATCH("S"&D13;range3;0))

On the other hand I tried to replace the formula in my VBA code with simpler one, like this one and that worked aswell:

HTML Selection.Cells(1).Offset(0, 5).Formula = "=a1+a2"

View 10 Replies
View Related
Sep 2, 2009

I'm using the below to code to insert a formula in cell E1, what am i doing wrong here.

View 5 Replies
View Related
Jul 9, 2008

Upon user making selection from data validation list in Active Row Selection & Column A : i would like to do the following (is possible)

,,,,,,,,,,,,,,,

Place formula in Active Cell Row & Column S

=MT4|BID! (followed by cell A1 but replace the "/" with "") followed by "m"

I have tried several combinations but with no success.

Also - where would i place this code so that it automatically updates the formula in Column S as soon as the user changes selection in Cell A?

View 9 Replies
View Related
Dec 4, 2006

Cell b2 contains the formula

=IF( COUNTIF(B$1:B2,B2)=1,MAX(A$1:A1)+1,"")

I want cell b3 to contain the formula

=IF(COUNTIF(B$1:B3,B3)=1,MAX(A$1:A2)+1,"")

I can do this within the spreadsheet by simply highlight and drag down to autofill and excel updates the formula references as I need

However - because the sheet gets very large (its a sort of rough database)

I dont fill in all the formulae on a blank sheet, but each time a record is entered using a VBA form I have the following working code copy the formula

ActiveCell.Offset(nextline, 0).Copy

ActiveCell.Offset(nextline + 1, 0).Select

ActiveSheet.Paste

However I dont want to use 'Active' - because I have to work out what cell is selected before this is executed and then reselect it after, which also causes the screen to flash when the active sheet changes so I tried the following which does not work

Worksheets(" Analysis").Range("A2").Offset(nextline, 0).Copy

Worksheets("Analysis").Range("A2").Offset(nextline + 1, 0).Paste

because 'object does not support this property or method' on the Paste.

I can save the code in a string and modify the string to generate the new code, but I cant find a way to assign the new formula to the next cell.

View 9 Replies
View Related
Aug 11, 2007

If I wish to amend the below code such that it must use the cell one row above minus the cell on the left, how should I go about it?

Eg,

If in cell C10, the formula is to use C9 minus B10.

If in cell C11, the formula is to use C10 minus B11.

mylogoff.Offset(0, 1).FormulaR1C1 = "=RC[-1]-RC[-2]

View 5 Replies
View Related
Nov 19, 2013

I have come across this wonderful piece of code that kind of accomplishes what I am after, to a point. Though I would like the output string to be displayed with a few extra characters.

Code:

Function Concat(rng As Range, Optional sep As String = " , ") As String

Dim rngCell As Range

Dim strResult As String

For Each rngCell In rng

If rngCell.Value "" Then

strResult = strResult & sep & rngCell.Value

End If

[code].....

I want the output to be:

["cell1" , "cell2" , "cell3" , "cell4" , "cell5"]

View 2 Replies
View Related
Jan 2, 2014

I have written the following code for blinking text.

But what I want is :

Suppose if I have a range of cells, in which I have text in red & green color.

Then whether it is possible to blink the text in red color only in a selected range ?

My Code :

Sub StartBlink()

With ThisWorkbook.Worksheets("Sheet1").Range("c3:c6").Font

If .ColorIndex = 3 Then ' Red Text

.ColorIndex = 2 ' White Text

Else

.colorindex = 3

[Code] ........

View 1 Replies
View Related
May 8, 2014

I am about to take on a rather large excel project for our company. The first part is coming up with how to deal with our drafting department's length inputs. In this project, our users will be entering lengths in a unique format. I have to convert that unique format to a standard Foot-Inch-Fraction format.

To try to keep the file size down and keep the complexity down, converting a cell formula to VBA so i can run this on a group of cells rather than repeating my code downward multiple rows on multiple sheets.

It is either this or come up with my own font that will convert it for me but I do not know where to start with that. How to take a stab at converting this to a VB code i can run?

A3 = 1.0108

B3 = 1'-1 1/2"

The code in B3 looks like this:

[Code] .......

An explanation of the unique format we use in our drafting department:

Basic Feet, Inch and Fraction format = 0 . 00 00 = Feet . Inch Fraction

The numbers left of the decimal point are feet. The first two numbers to the right of the decimal point are inches and the next two are sixteenths of an inch.

Examples:

4β-2" = 4.0200

15β-5 1/4" = 15.0504

4β-11 3/8" = 4.1106

0β-1 15/16" = 0.0115

View 5 Replies
View Related
Dec 3, 2007

If I have a cell containing a formula say c1= sum(a1..a10) and the output appears in a50. how do I colour code it so I know the formula in c1 is linked to the output in a50?

View 5 Replies
View Related
Jun 26, 2008

Application. ScreenUpdating = False

For FormulaRemake = 2 To 2000

Worksheets("Data"). Range("D" & FormulaRemake).Formula = ""=If(ISERROR(Data!W"" & FormulaRemake - 1 & "")"" & ""=True,"",Data!W"" & FormulaRemake - 1 & "")""

Next

Application.ScreenUpdating = True

I'm having troubles with the syntax for the .Formula part. I read that when you do this you're supposed to double quote everything, except if you need a "" in it...?

Should look like this when done right: =IF(ISERROR(Data!W1)=TRUE,"",Data!W1) Also is there anything besides ScreenUpdating that will make this code run faster?

View 3 Replies
View Related
Jul 19, 2013

I am trying to write the code to;

1) change to a different sheet

2) select a specific cell range

3) save that range as a text / xml file with a filename derived from a cell outside the given range

Here is where I have got to so far, but it fails

Private Sub Export_Click()

Sheets("Parsed Data").Select

ThisFile = Range("B1").Value

ActiveWindow.SmallScroll Down:=-15

Range("A1:A41").Copy

SaveAs Filename:=ThisFile, _

FileFormat:=xlTextMSDOS

Application.WindowState = xlMinimized

End Sub

View 2 Replies
View Related
Feb 9, 2014

I am trying to do the following with VBA.

What i need is to find out the last cell with data and then selecting the whole range and copying it.

Please see the below.

As you can see, the column with the "longest" data range is B9,C9,D9,E9.

I need a VBA code to detect which Column has the longest Data and from there copy the entire range.

Hence, in this case, the range to be copied is From A2:J9.

Column A

Column B

Column C

Column D

Column E

Column F

Column G

Column H

Column I

Column J

1

2

ttt

rrr

m

vvv

gg

ff

fff

fff

fff

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

Hence,in this case, the range to be copied is From A2 to J14.

Column A

Column B

Column C

Column D

Column E

Column F

Column G

Column H

Column I

Column J

1

2

hjhjh

ghj

gh

ghj

ghj

ghj

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

View 5 Replies
View Related
May 27, 2008

I'm trying to use an offset from a Named Range as my source cell in a vlookup but get a -1004 Object not defined error. When Debugged the Range.Formula appears to be blank when queried. Using Record a Macro the Reference to a named range worked fine but I could not test for an offset or the use of the range reference. What can I do to use to make this work

Range.Formula="=vlookup(Range(""SomeName"").Offset(1,0),DataRange,2,False)"

View 7 Replies
View Related
Jun 18, 2014

Here is the code I'm working on:

I want this code to replace the value of s with the value of a cell.

sub Macro2()

Dim s As String

s= value of (cell F2)

Range("I8").Select

ActiveCell.FormulaR1C1 = "='[(s).xlsm]Payroll Computation '!R8C11"

End Sub

View 5 Replies
View Related
Jul 15, 2014

the following two statements return the error "Application-defined or object-defined error"

Code:

Sheets("Purchase").Range("PurchaseTax").FormulaR1C1 = "=IF(RC[-1]0,ROUND(RC[-1]/11,2),"")"

Sheets("Purchase").Range("FreightTax").Formula = "=IF(FreightCharge0,ROUND(FreightCharge/11,2),"")"

View 2 Replies
View Related
Mar 4, 2008

I'm having trouble getting my random number generator functions to use my variables that are defined by text box inputs. I can mouse over the variables in the code and they have the correct values, with the excpetion of where they are listed in the functions. I'm sure I'm missing something simple, thanks in advance for any help!

Private Sub cmdPopulate_Click()

StdDev = txtStdDev.Value

RandomNum = txtRandomNum.Value

Mean = txtMean.Value

lambda = txtLambda.Value

OriginCell = txtOriginCell.Value

If cmbDistributions.Value = "Normal" Then .................

View 9 Replies
View Related
May 23, 2014

When I enter data in the cells A1 and B1, C1 needs to calculate the result. (not copy and paste)

For examle: I have formula C1=(A1+B1)/2

C column for formula, but shows result only when there is a data in A and B

View 7 Replies
View Related
Mar 5, 2014

The idea is to select an item i one cell, which in return will affect the following cells with the nutritional values. So far so good. I would then like, if a given amount is entered, it calculates the values.

A food item is typed in Cell A. The following cells will Index Match a table (on a different sheet), importing calculation formulas based on the food items nutritional value (Cells C - G). If an amount is typed in Cell B (i.e. 100 grams) the following cells will then calculate the correct nutritional values.

i learned to make an INDEX MATCH function, so that when i type "Gulerod" or something like that, the following cells import information from the Table tab... When the table contains fixed values, this works just fine. However - i tried to make the table (the cells) with calculation formulas (i.e. =SUM(4*B3))... this means the values in the tables are 0 untill a value is typed in B3 (in this example).

... however when i do the Index Match in my main tab, only the "0"'s are imported, and no matter what value i enter in B3 in the main tab, the following cells remains with the fixed value 0.

... so my question is - is it even possible to have the Index Match function import the calculation formula from the table and have it work in the main tab as well? Or is there any other way to make this work in Excel? Basically - to have the main sheet find the relevant data to use for calculation on a different tab/sheet, and then do the actually calculations on the main tab/sheet.

View 5 Replies
View Related
Aug 22, 2012

I am using this code and it works fine:

Dim MyData As Range

Dim MyResult As Range

Set MyData = Range("E1:E1000000")

Set MyData2 = Range("F1:F1000000")

Set MyResult = Range("J4")

MyResult.Select

Selection.Formula = "=COUNTIFS(" & MyData.Address & ",""=Kim""," & MyData2.Address & ",""=done"" )"

Is there any way I can change the code so that it automatically finds the last cell as Im using Range("E1:E1000000") and Range("F1:F1000000") because there will not be more than 1000000 entries.

View 2 Replies
View Related
Apr 17, 2008

The loop is putting the correct formula into the cell - but THEN... - I wish to (within the loop and before it moves on) check if the value is equal to OR greater than 1 - if it is, make it a value of 1 (this '1' is then used at the bottom of the column of data to give a total). I need to do this before it moves onto the next cell. What am I doing wrong? Is it because once it puts formula in the cell, it then moves down - do I need to select the cell again first? As I had originally posted on this site - link: url]http://www.excelforum.com/showthread.php?t=641970[/url]

View 2 Replies
View Related
Apr 18, 2008

I'm trying to set a cell on one sheet to be equal to the product of two cells on another sheet. The problem is that one of the cells on the other page is dependent on the variable T. This is what I've got and it's giving me errors

Worksheets("Output").Range("K14").Formula = "Worksheets("Calcs").Range("D17")*worksheets("Calcs").Range("D17").Offset(10+T,0)"

When I record a macro it gives me this, but again, I need the last cell in terms of "T"

ActiveCell.FormulaR1C1 = "=Calcs!R[3]C[-7]*Calcs!R[14]C[-7]"

View 3 Replies
View Related
Apr 24, 2008

Hello I'm looking for some clarification about how to use "= SUM(RC:RC)". I don't understand what the RC:RC represents. I thought that this was the directions for where to "position" the formula, but I think I'm missing something.

I was able to include the correct cells that I need summarized, but the answer is not right; it's zero.

Public Sub SubColumn(CritStr As String) ...

View 8 Replies
View Related