Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8198709
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T06:00:28+00:00 2026-06-07T06:00:28+00:00

(VB Express Level: Beginner) I want to do following, A column from Workbook 1

  • 0

(VB Express Level: Beginner)

I want to do following,

A column from Workbook 1
a

b

c

d

A column from Workbook2
e

f

g

h

Output to a single cell

ae+bf+cg+dh

(The output is a Sumproduct.)

There are 44 rows in workbook 1 and 44 rows in workbook 2. But there are 3 columns in workbook 1 and 104 columns in workbook 2. Each column in workbook 3 must be multiplied with 104 columns from workbook 2.

Following is my effort, which writes sames values in all the cells of a column. My understanding is my for loop is wrong somewhere. But I am not able to figure out what is wrong.

'link to workbooks
oWB5 = oXL5.Workbooks.Open("D:\1.xlsx")
oWB6 = oXL6.Workbooks.Open("D:\2.xlsx")
oWB7 = oXL7.Workbooks.Open("D:\outputs.xlsx")

'link to worksheets
oSheet5 = oWB5.Worksheets("Inputs")
oSheet6 = oWB6.Worksheets("Coef")
oSheet7 = oWB7.Worksheets("Sheet1")

' ranges to be considerd,
' oWB5 range C22 to C66
' oWB6 range C3 to C47
' oWB7 range C2 to C104 (because there are 104 columns in oWB6) 

'multiplication of ranges

For j = 3 To 47
For i = 2 to 104
For k = 2 to 4 
For l = 22 to 66
oSheet7.Cells(i, k).Value = (oSheet5.Cells(l, k).value * oSheet6.Cells(j, i+1).value) + (oSheet5.Cells(l+1, k).value * oSheet6.Cells(j + 1, i+1).value)
Next
Next
Next
Next 

Help will be really appreciated. I am struggling with this for two days now.

Source Worksheets

required output

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T06:00:30+00:00Added an answer on June 7, 2026 at 6:00 am

    Here is a simple method using the Excel’s SUMPRODUCT formula. This way you let Excel do the dirty work for you. The advantage of this is that it saves you a lot of looping 🙂

    TRIED AND TESTED

    Imports Excel = Microsoft.Office.Interop.Excel
    
    Public Class Form1
    
        Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
            Dim xlApp As New Excel.Application    
            Dim oWB5 As Excel.Workbook = xlApp.Workbooks.Open("C:\1.xlsx")
            Dim oWB6 As Excel.Workbook = xlApp.Workbooks.Open("C:\2.xlsx")
            Dim oWB7 As Excel.Workbook = xlApp.Workbooks.Open("C:\outputs.xlsx")    
            Dim oSheet7 As Excel.Worksheet = oWB7.Worksheets("Sheet1")
    
            With oSheet7
                For i = 1 To 8
                    For j = 1 To 104
                        Dim Col1Nm As String = Split(.Cells(, j).Address, "$")(1)
                        Dim Col2NM As String = Split(.Cells(, i).Address, "$")(1)
                        .Cells(i, j).Value = xlApp.Evaluate("=SUMPRODUCT(([1]Inputs!" & Col1Nm & "1:" & _
                        Col1Nm & "44)*([2]Coef!" & Col2NM & "1:" & Col2NM & "44))")
                    Next
                Next    
            End With
    
            '~~> Close workbook and quit Excel
            oWB5.Close (False)
            oWB6.Close (False)
            oWB7.Close (True)
    
            xlApp.Quit()
    
            '~~> Clean Up
            releaseObject (oWB5)
            releaseObject (oWB6)
            releaseObject (oWB7)
            releaseObject (xlApp)
    
            MessageBox.Show("done")
        End Sub
    
        Private Sub releaseObject(ByVal obj As Object)
            Try
                System.Runtime.InteropServices.Marshal.ReleaseComObject (obj)
                obj = Nothing
            Catch ex As Exception
                obj = Nothing
            Finally
                GC.Collect()
            End Try
        End Sub
    End Class
    

    IMP NOTE: If your actual file names are not 1.xlsx and 2.xlsx then change this part of the code

    xlApp.Evaluate("=SUMPRODUCT(([1]Inputs!" & Col1Nm & "1:" & _
    Col1Nm & "44)*([2]Coef!" & Col2NM & "1:" & Col2NM & "44))")
    

    Replace

    1. [1] by [Actual File Name]
    2. [2] by [Actual File Name]
    3. Inputs by [Actual Sheet Name] and
    4. Coef by [Actual Sheet Name]
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can I express to PostgreSQL that I want values simultaneously from several hierarchical
I tried using : sp_send_dbmail But I got the following error: Msg 15281, Level
We are talking Isolation Level here, namely concurrency in relation to an Express MSSQL
Are there any ways to secure stored procedure consistency at the software level, so
I run the following query SELECT * FROM ( SELECT * FROM Client );
I downloaded the 53.5 MB setup of SQL Server 2005 Express from this URL:
So I established a connection from my SQL Server 2008 Express Edition to our
I'm making switch from MySQL to SQL Server 2008 Express and can't seem to
I have an express server which I am testing using vows. I want to
i want to schedule a daily backup with SQL Server Express by using window

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.