Sumproduct Formula in VBA

Status
Not open for further replies.

majesteleri

New Member
Joined
Aug 18, 2023
Messages
2
Office Version
  1. 2019
Platform
  1. Windows
Hi everybody,

I have a Run-time error 1004 problem at this row = ActiveCell.Formula = "=SUMPRODUCT(" & StrRange1 & ")"

What is the problem ?

VBA Code:
Sub CLImproved()

  Application.ScreenUpdating = False
  Dim TLTOPLAMLAR As Integer
  Dim StrRange1 As String
  Dim Kur As String
  Dim rng As Range
  
    
  ActiveWorkbook.Sheets("Keşif Özeti").Select

    firmasayisi = Range("A1").Value
        Cells.Find(What:="Sıra" & Chr(10) & "No", After:=ActiveCell, LookIn:=xlFormulas2, _
        LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
        MatchCase:=False, SearchFormat:=False).Activate
    
    kesifilksatir = ActiveCell.Row + 1
    
    Cells.Find(What:="TL TOPLAMLAR", After:=ActiveCell, LookIn:=xlFormulas2, _
        LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
        MatchCase:=False, SearchFormat:=False).Activate
    TLTOPLAMLAR = ActiveCell.Row
    Range("A5").Select
        Cells.Find(What:="Kur", After:=ActiveCell, LookIn:=xlFormulas2, _
        LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
        MatchCase:=False, SearchFormat:=False).Activate
    Kur = ActiveCell.Column
    Sheets("Format").Select
    Range("X1").Value = Kur
    Kursutun = Range("X2").Value
    Sheets("Keşif Özeti").Select

    
        Cells.Find(What:="Miktar", After:=ActiveCell, LookIn:=xlFormulas2, _
        LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
        MatchCase:=False, SearchFormat:=False).Activate
    Miktar = ActiveCell.Column
        Sheets("Format").Select
    Range("X1").Value = Miktar
    Miktarsutun = Range("X2").Value
    Sheets("Keşif Özeti").Select
  
    kesifsatirsayisi = kesifsonsatir - kesifilksatir
    Range("A5").Select
For Z = 1 To firmasayisi
    Cells(kesifilksatir - 1, Sonislemsutun + 1).Select
            Cells.Find(What:="Kur", After:=ActiveCell, LookIn:=xlFormulas2, _
        LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
        MatchCase:=False, SearchFormat:=False).Activate
    Kur = ActiveCell.Column
For i = 0 To 3

Cells(kesifilksatir - 1, Sonislemsutun + 1).Select

    Cells.Find(What:="Malzeme" & Chr(10) & "Birim Fiyatı", After:=ActiveCell, LookIn:=xlFormulas2, _
        LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
        MatchCase:=False, SearchFormat:=False).Activate
MBF = ActiveCell.Column + i
    Sheets("Format").Select
    Range("X1").Value = MBF
    MBFsutun = Range("X2").Value
    Sheets("Keşif Özeti").Select

StrRange1 = Miktarsutun & kesifilksatir & ":" & Miktarsutun & TLTOPLAMLAR - 1 & "," & Kursutun & kesifilksatir & ":" & Kursutun & TLTOPLAMLAR - 1 & "," & MBFsutun & kesifilksatir & ":" & MBFsutun & TLTOPLAMLAR - 1 & ")"
'''strRange1 = Chr(64 + Miktarsutun) & kesifilksatir & ":" & Chr(64 + Miktarsutun) & TLTOPLAMLAR - 1 & "," & Chr(64 + Kursutun) & kesifilksatir & ":" & Chr(64 + Kursutun) & TLTOPLAMLAR - 1 & "," & Chr(64 + MBFsutun + i) & kesifilksatir & ":" & Chr(64 + MBFsutun + i) & TLTOPLAMLAR - 1
strRange2 = MBFsutun & TLTOPLAMLAR
'''TCFormul = "=SUMPRODUCT(" & strRange1 & ")"
Range(strRange2).Select
ActiveCell.Formula = "=SUMPRODUCT(" & StrRange1 & ")"
Next i
.
.
.
.
.
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
Test first, by replace this
VBA Code:
ActiveCell.Formula = "=SUMPRODUCT(" & StrRange1 & ")"
with
Code:
ActiveCell.Value = "SUMPRODUCT(" & StrRange1 & ")"
what value is in ActiveCell now? Is it a working sumproduct?
 
Upvote 0
Duplicate to: Excel VBA Set Activecell Formula With String

In future, please do not post the same question multiple times. Per Forum Rules (#12), posts of a duplicate nature will be locked or deleted.

In relation to your question here, I have closed this thread so please continue in the linked thread. If you do not receive a response, you can "bump" it by replying to it yourself, though we advise you to wait 24 hours before doing so, and not to bump a thread more than once a day.
 
Upvote 0
Status
Not open for further replies.

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top