VBA Range Formula

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Can anybody tell me how to get this to work? In other words, how do I
reference my procedure variables in a cell formula? Thanks!

Sub Marktest()
Set b = Cells.Find("Total", , xlValues)
Set c = Range("C5")

Range(b.Offset(-1, 2), c).Formula = _
"=sumproduct(($B5=Range(b.Offset(-7, 1), b.Offset(-5, 1)))*$C$1:$C$3)"
End Sub
 
I'd do something like:

Option Explicit
Sub Marktest2()

Dim myRng As Range
Dim b As Range
Dim c As Range

With ActiveSheet
Set b = .Cells.Find("Total", , xlValues)
Set c = .Range("C5")

Set myRng = .Range(b.Offset(-7, 1), b.Offset(-5, 1))

.Range(b.Offset(-1, 2), c).Formula = _
"=sumproduct(($B5=" & myRng.Address(external:=True) & ")*$C$1:$C$3)"
End With

End Sub
 

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