Thread: VB Code
View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.misc
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default VB Code

So instead of starting multiple new threads, why not just follow up with more
information?

I'm confused about if you want to divide by the value in the row with total or
the previous row.

Option Explicit
Sub testme()

Dim FoundCell As Range
Dim wks As Worksheet

Set wks = ActiveSheet

With wks
With .Range("A:A")
Set FoundCell = .Cells.Find(What:="total", _
After:=.Cells(.Cells.Count), _
LookIn:=xlValues, _
LookAt:=xlPart, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)

End With

If FoundCell Is Nothing Then
MsgBox "Total not found in column B!"
Exit Sub
End If


.Range("C2:C" & FoundCell.Row - 1).FormulaR1C1 _
= "=rc[-1]/r" & FoundCell.Row & "c[-1]"
'or??
'= "=rc[-1]/r" & FoundCell.Row - 1 & "c[-1]"

End With
End Sub


Stan wrote:

Unfortunately it didn't because data appears after the word "Total" in column
A. I'm still trying to find out how to lock a cell by using code. You know
the $B$24.

"Dave Peterson" wrote:

Yesterday's response didn't help?

Stan wrote:

I'm trying to divide Cell C2 by the data in the last row in Column B. Can
anyone help me with the VB coding for this?

ActiveCell.FormulaR1C1 = "=RC[-1]/ "

Also, after I've done the division I'm trying to write code to auto-fill
from cell C2 down to the row that contains the word "Total" in column A. In
other words, if the word "Total" appears in Cell A41 then I would like to
have code that auto-fills cells C2:C41. The problem I'm having is the word
"Total" will appear only once but in different rows within column A each day.
Any thoughts?


--

Dave Peterson


--

Dave Peterson