Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Watch for linewrap.
I need to edit a cell with a number, add a = before it, a + after it and then the number from the cell to the right of it. There was a similar post about taking a cell content and adding a number that was asked for: Sub CreateFormula() Dim dblNum As Double, dblAdd As Double dblNum = ActiveCell.Value dblAdd = Application.InputBox("Please enter the number to add.", Type:=2) ActiveCell.Formula = "= " & dblNum & "+" & dblAdd & "" End Sub How do I adjust it to put in another adjacent cell instead of the requested number? |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Sub CreateFormula()
With ActiveCell .Formula = "=" & .Value & "+" & .Offset(0,1).Value End with End Sub -- Regards, Tom Ogilvy " wrote: Watch for linewrap. I need to edit a cell with a number, add a = before it, a + after it and then the number from the cell to the right of it. There was a similar post about taking a cell content and adding a number that was asked for: Sub CreateFormula() Dim dblNum As Double, dblAdd As Double dblNum = ActiveCell.Value dblAdd = Application.InputBox("Please enter the number to add.", Type:=2) ActiveCell.Formula = "= " & dblNum & "+" & dblAdd & "" End Sub How do I adjust it to put in another adjacent cell instead of the requested number? |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
That worked. Now I need it to step through a range of rows, and if A 1
then perform the function until A is not populated Tom Ogilvy wrote: Sub CreateFormula() With ActiveCell .Formula = "=" & .Value & "+" & .Offset(0,1).Value End with End Sub -- Regards, Tom Ogilvy " wrote: Watch for linewrap. I need to edit a cell with a number, add a = before it, a + after it and then the number from the cell to the right of it. There was a similar post about taking a cell content and adding a number that was asked for: Sub CreateFormula() Dim dblNum As Double, dblAdd As Double dblNum = ActiveCell.Value dblAdd = Application.InputBox("Please enter the number to add.", Type:=2) ActiveCell.Formula = "= " & dblNum & "+" & dblAdd & "" End Sub How do I adjust it to put in another adjacent cell instead of the requested number? |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
For RowNdx = 50 To 1 Step -1
With Cells(RowNdx,"a") If .Value 1 Then .Formula = "=" & .Value & "+" & .Offset(0, 1).Value End If End with Next End Sub If you are checking column A, but wish to put the formula in say column E For RowNdx = 50 To 1 Step -1 With Cells(RowNdx,"a") If .Value 1 Then with .Offset(0,4) .Formula = "=" & .Value & "+" & .Offset(0, 1).Value end With End If End with Next End Sub The reason your code doesn't work is you never change the activecell. -- Regards, Tom Ogilvy " wrote: I tried For RowNdx = 50 To 1 Step -1 If Cells(RowNdx, "a").Value 1 Then With ActiveCell .Formula = "=" & .Value & "+" & .Offset(0, 1).Value End With End If Next End Sub But for some reason it stays in the row it's in and performs the operation 50 times. Why won't it go to another row? wrote: That worked. Now I need it to step through a range of rows, and if A 1 then perform the function until A is not populated Tom Ogilvy wrote: Sub CreateFormula() With ActiveCell .Formula = "=" & .Value & "+" & .Offset(0,1).Value End with End Sub -- Regards, Tom Ogilvy " wrote: Watch for linewrap. I need to edit a cell with a number, add a = before it, a + after it and then the number from the cell to the right of it. There was a similar post about taking a cell content and adding a number that was asked for: Sub CreateFormula() Dim dblNum As Double, dblAdd As Double dblNum = ActiveCell.Value dblAdd = Application.InputBox("Please enter the number to add.", Type:=2) ActiveCell.Formula = "= " & dblNum & "+" & dblAdd & "" End Sub How do I adjust it to put in another adjacent cell instead of the requested number? |
#6
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Excellent!
You have saved the day. Tom Ogilvy wrote: For RowNdx = 50 To 1 Step -1 With Cells(RowNdx,"a") If .Value 1 Then .Formula = "=" & .Value & "+" & .Offset(0, 1).Value End If End with Next End Sub If you are checking column A, but wish to put the formula in say column E For RowNdx = 50 To 1 Step -1 With Cells(RowNdx,"a") If .Value 1 Then with .Offset(0,4) .Formula = "=" & .Value & "+" & .Offset(0, 1).Value end With End If End with Next End Sub The reason your code doesn't work is you never change the activecell. -- Regards, Tom Ogilvy " wrote: I tried For RowNdx = 50 To 1 Step -1 If Cells(RowNdx, "a").Value 1 Then With ActiveCell .Formula = "=" & .Value & "+" & .Offset(0, 1).Value End With End If Next End Sub But for some reason it stays in the row it's in and performs the operation 50 times. Why won't it go to another row? wrote: That worked. Now I need it to step through a range of rows, and if A 1 then perform the function until A is not populated Tom Ogilvy wrote: Sub CreateFormula() With ActiveCell .Formula = "=" & .Value & "+" & .Offset(0,1).Value End with End Sub -- Regards, Tom Ogilvy " wrote: Watch for linewrap. I need to edit a cell with a number, add a = before it, a + after it and then the number from the cell to the right of it. There was a similar post about taking a cell content and adding a number that was asked for: Sub CreateFormula() Dim dblNum As Double, dblAdd As Double dblNum = ActiveCell.Value dblAdd = Application.InputBox("Please enter the number to add.", Type:=2) ActiveCell.Formula = "= " & dblNum & "+" & dblAdd & "" End Sub How do I adjust it to put in another adjacent cell instead of the requested number? |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
In cell editing | Excel Discussion (Misc queries) | |||
Editing in Cell | Excel Discussion (Misc queries) | |||
Editing in a cell | New Users to Excel | |||
Disabling Cell Editing | Excel Programming | |||
Cell Editing | New Users to Excel |