

Cell value will be either zero or 2 both a result of a formula in the cell. I need to find the first cell value with value 2 then sum cells to the right until cell 2. Looking to code a search of a row of cells that will sum the values of the cells containing the value 2. Sheets(“Removed from wait list 2015”).SelectĪctiveCell.FormulaR1C1 = Application.UserName I use A1 as my reference point from worksheet B. Somewhere in my code it does not continue the offset, everytime i remove it replaces the current line. I am removing rows from worksheet A to worksheet B to be archived. You would probably want to format the salary for currency, but this is the general idea. MsgBox(strFirstName & " " & strLastName & ": Your new salary is " & dblSalary) StrLastName = ActiveCell.Offset(0,1).ValueĪctiveCell.Offset(0,2).Value = dblSalary * 1.05 'give a 5% raise It is easier to program and way faster to execute. You can loop through a list much more efficiently with Offset. If you are in cell G254, the code ActiveCell.Offset(-3,-2).Select will select E251 (3 rows up and 2 columns left). If you want to offset to a column to the left of you or a row above you, use a negative number. This is far more efficient than selecting the cell two columns to the right, processing your data, then remembering to select two columns to the left and continue. If you are in cell D254, the code above will reference the cell F254 and read its value into the variable strMyValue. So if you want to stay in the current cell and read a value two columns to the right, you could use syntax like the following: strMyValue = ActiveCell.Offset(0,2).Value The “Range(“A1″)” clause is not necessary. Translated into English, it takes the current cell (ActiveCell) and selects the row that is one row down from the current row and in the same column. Offset clause when you record a macro using relative references: ActiveCell.Offset(1, 0).Range("A1").Select

There are times when you are processing a list when you might want to look at the values in the same row, but a couple of columns over. If you are watching the sheet, the values simply appear. This is way faster than selecting the cell, changing the value, selecting the next cell, etc.

Whatever cell you were in when you entered the loop is where you are when you leave the loop. Cells works best with calculated cells, especially when you couple it with a loop: For i = 1 to 10Ĭells(i, 1).value = i ' fill A1 through A10 with the value of i To select a cell in Excel, you have two basic methods: RANGE and CELLS: Range ("A1").Select Range("RangeName").Select Cells(3, 4).Select 'Selects Row 3, Column 4, i.e.
