Insert Relative R1C1 SUM Formula Into Cell Via Macro Code
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.
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.
I am trying to figure out how to use a variable as a row number for use in a range name and/or a pivot table range. Right now I have a range of R571C17, but the row number will change with each use of the pivot table formation macro.
I am using follwoing vb code to enter formula to sum a range. However it is giving sum of different range.
Cells(Row, Column).FormulaR1C1 = "=SUM(R[" & a & "]C[" & b & "]:R[" & x & "]C[" & y & "])"
Where a, b , x and y are variables containg starting row, starting column, last row and last column value like a=19; b=3; x=24 and y=3. When i check the formula in that cell, it appears as Sum(F25:F30)
I am updating a wsheet via a form using vb to locate next empy row etc. The issue I have is with the formula's no matter how I try I cannot get the formula to increment with each row. I know I can drag and auto fill on the sheet but I want to use vb if poss. eg
Previous entry to sheet:- A1=1 B1=2 c1=A1+B1(formula)
New entry via form selecting next empty. A2=(updated from form.) B2=(Updated from form.) C2=(Update code VB)
This is all okay and functional the problem starts from here I so far have been unable to increment the formula in c1 from A1+B1 to A2+B2 using vb, is this possible or am I just chasing my tail.
When I first started using excell I was relatively good at it, however a few changes were made. The main one being for excell 2002 was the collumns were not by letter. A minor problem that I managed to get past. However the next was a function issue. Before I remembered a way to total rows with a simple function like =b3*c3, which worked for the first one. Then, from that point, I could copy that formula and paste it to all of the cells in the collum in which the forumula changed for individual cells to =b4*c4, =b5*c5, etc.
My questions are simple. Is there a way that I can do this on Excell 2002 without having to do it on a cell by cell basis, and is there a way to change collumns back to letters.
I've attached the spreadsheet in which I want to figure this out on. The goal, is to total price and quantities sold into the totals section without doing it on a cell by cell basis.
I am using VB to insert a function into a cell on an excell worksheet. The relative references work fine. For the absolute reference, I want to use a named range (LowTotal). If I simply put the name into the function, then I just get the name as text in the function. The second insert formula is were the named range is intended to go. Here is the code so far...
I need to know how to use the varriable name in the .formulaR1C1, so that VB knows it is a variable and not just text....
I have a report that I run off a database and extract to Excel.
It has 3 fields: Title; FirstName; LastName. For example sake lets say they are in columns A, B, C. Now in D I have a fieldname of FullName and in D2 onwards the formula: =A2&" "&B2&" "&C2.
Now I currently manually type the formula and drag it down to the same row as the last entry in the first 3 columns so that I get the full title in one cell.
I wanted to know how I could enter the the formula above in column D so that it automatically does this for me?
I tried to record a Macro as a test for column D setting the field name in D1 and the formula in D2 and got the following:
I am using a For Next statement that doesn't return the results for all the rows. The statement is as follows:
For Row = 1 To 100 If ActiveCell.Value = "CHANGE" Then ActiveCell. Offset(0, 2).Range("A1").Select ActiveCell.FormulaR1C1 = "=RIGHT(""0000""&RC[-1],20)" ActiveCell.Offset(1, 0).Range("A1").Select ElseIf ActiveCell.Value <> "CHANGE" Then ActiveCell.Offset(1, 0).Range("A1").Select Else: Range("A1").Select Exit For
End If Next
Range("A1").Select
I hope I did that according to the rules. It only returns the result in the first cell that does have a value of "CHANGE". It seem to be going through the entire range of cells, but I'm not getting any results.
using a macro im trying to paste in a sum formula, however this will be pasted onto different sheets and the number of records will be different for each so i cannot use absolute locations. the only constant is that all ranges will start in row I9. when it runs the following code
it fills in =SUM('I8':I13) how can i make it insert it without the ' ' around the I9? and how can i select the two cells? (again, cannot be absolute..)
I want my column to be populated by formula using VBA. Let's say on row1, the formula is = SUMIF(mysheet!$L:$L,$A1&C$1&"09",mysheet!$M:$M). And on row 2, the formula is =SUMIF(mysheet!$L:$L,$A2&C$1&"09",mysheet!$M:$M). And on row 3, the formula is =SUMIF(mysheet!$L:$L,$A3&C$1&"09",mysheet!$M:$M). And this is done up to the last row. How do I do this?
I have a project coming up where I will receive tables in a certain format. I want to be able to create a macro that well create a chart based on a single inputted cell (start of data). The chart will have 4 series and five values per series. See the link below for sample data! The first data point is not in the same place in the sheet, but the table will have the rest of the data relative to that!
I'm importing comma delimited files into Excel. These files will contain formulas, but do not know on which row they will end up in once imported. My formula's need to reference the row they have been pasted to. For example, If I paste the formula on Row 2 the formula would be =A2+B2
Row 3 =A3+B3
However, since these formulas are coming in via a non-excel file, I need the cell reference to be dynamic. Something along the lines of =A#+B# where # would be interpreted by Excel as the current row the formula is on. (I know that '#' isn't correct.)
I currently have a list of totals that i want to easily be able to change the cells that make up this total.
I have been trying to set up one cell that contains the formula and then the remaining totals below are linked to this cell. Thus I change the formula in the top cell all the other totals also change.
I'm working on my first real macro - so I'm a greenhorn. I've spent a few hours trying to research a solution, but most threads are too technical for me so I'm hoping someone can really help me out.
I am trying to use a formula that references a cell that changes day to day from when I use the macro. I need to use a formula which grabs from a cell in a non concrete location. Let me try and show you what I mean.
I have a list of University courses listed in Sheet1. Column A contains a unique course code. If there is a problem with a course, a second worksheet (called Anomalies) contains the same unique course code with description of the problem(s).
What I'm trying to do is: in Sheet 1, create a hyperlink to the relative cell in Sheet 2 that shows the course code and description. I've gotten close, but am not sure how I can do this without having to update two formulas. In short, I can't find a way to combine the two formulas.
What I've done is the following: in Sheet 1, column B, created a HYPERLINK formula, thus: =HYPERLINK("#"&CELL("address",INDIRECT(C54)),A54)
Column C contains a formula to lookup the relative position in the Anomalies worksheet, which can be referenced back to the HYPERLINK formula, thus: =("Anomalies!A"&MATCH(A54,Anomalies!A:A,0))
Sheet1 is fairly static, but Sheet2 (Anomalies) is being updated all the time. I could just hide column C and then column B will update based on that, but I'd prefer a cleaner solution.
I've tried joining the two formulas, by replacing the INDIRECT part with the second formula, as per the following: HYPERLINK("#"&CELL("address","Anomalies!A"&MATCH(A54,Anomalies!A:A,0)),A54) but I get an error.
I have recorded macros in the attached file to highlight cells that contain matching initials by using conditional formatting on the first cell and copying it to the remaining cells. The problem is that if rows are inserted above that change the first cell reference then the macro no longer works properly. Is there a way to use a relative cell reference within the macro? The macro buttons are in cells A4 to A13. I have no VB experience and created the macros by recording keystrokes and using tips found in this forum.
I am writing a macro that populates some columns from other worksheets, and populates other columns with formulas. One of these formulas is a text string that includes a three digit number, with leading zeros if needed. The following formula works perfectly when typed directly into the cells:
But this formula triggers a error message "Compile error: Expected: end of statement" when inserted in my sub. The "00" is highlited when the error message appears.
Im looking for code for a button that asks for a Record number, and it will delete the record. But the record number is written in cells as 'Record No.1' 'Record No.2' etc. But i want the messagebox to ask for a single number and it would delete that record. Now the position of the records is what will be the difficult bit about this code, but it has a pattern.
For Record No.1 i need deleting cells C2:J100 For Record No.2 i need deleting cells L2:S100 For Record No.3 i need deleting cells U2:AB100
If anyone could give me a bit of code that works for these 3 then i could waste a load of time filling the rest of them out.
The problem I am trying to solve is to have a cell return a cell value based on another linked cell. The cells I want to link are in separate tabs or could be another workbook.
For example if cell A5 in sheet2 is linked to A20 in sheet1...A5 has formula(=Sheet1!A20). I want the next cell B5 to look at A5 and return the value of cell Sheet1!D18.
So in essence I want the second cell to look at the first cell and return a value that is 3 columns over and 2 rows up.
I was wondering if i could get a hand with inserting a file. Is there a way to insert the file and have it placed a relative distance from the insert button without using cell references?