insert amount into first emtpy cell

  • Thread starter Thread starter derekc
  • Start date Start date
D

derekc

i have already have something written out to subtract cells fro
eachother in a row until it hits a neg. number. then it stops on tha
last pos number. i want to have the number left over from th
subtractions to be added at the end of the row in the first emtp
cell.
so if a1 - b1 - c2 = 23 i want 23 in the first empty cell in that row
and so it will do it for each row. i have the subtraction part down
just need something to tell it to add whats left over into the firs
emtpy cell on the row. if any info needed just reply. thank
 
try
Sub sumrow()
mr = ActiveCell.Row
x = Cells(mr, Columns.Count).End(xlToLeft).Column + 1
Cells(mr, x) = Application.Sum(Range(Cells(mr, "a"), Cells(mr, x - 1)))
End Sub
 
Derek,

Assuming that you have the value in variable myVal

Range("A1").Offset(0,Cells(1,Columns.Count).End(xlToLeft).Column).Value
= myVal

and so on for the other rows

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 
tried don's way and it gave me a zero for first row and that was it. an
0 wasnt right either and i dont have myVal. this is what i have s
far.

Private Sub launchbutton_1_Click()

lastRow = Worksheets("First Sheet").UsedRange.Row - 1
Worksheets("First Sheet").UsedRange.Rows.Count
lastCol = Worksheets("First Sheet").UsedRange.Column - 1
Worksheets("First Sheet").UsedRange.Columns.Count

With Worksheets("First Sheet")

For x = 2 To lastRow
On Error GoTo Skip
y = 7
runTot = 0
parts = .Cells(x, 7).Value
Do Until y = lastCol _
Or runTot > parts
y = y + 1
runTot = runTot + .Cells(x, y).Value
Loop
If runTot > parts Then
For z = 8 To y - 1
.Cells(x, z).Interior.ColorIndex = 6
Next z
ElseIf y = lastCol Then
For z = 8 To y
If .Cells(x, z).Value <> "" Then
.Cells(x, z).Interior.ColorIndex = 6
End If
Next z
End If
Skip:
Next x

End With

End Su
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top