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 8058631
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T09:25:15+00:00 2026-06-05T09:25:15+00:00

I have an Excel Spreadsheet that I generated dynamically using SQL and VB.NET. The

  • 0

I have an Excel Spreadsheet that I generated dynamically using SQL and VB.NET. The number of columns (2) will never change, however the number of records will change according to what data the user has specified. After the SQL has run and has filled the spreadsheet, I need to add a record at the bottom of the table that displays the total(int value) of the records in column 2.

Something like:

xlSheet.Range(bottom record, column1) = “Total”
xlSheet.Range(bottom record, column2) = Sum of all above records in column 2

I am using VS 2010 and Excel 2010.

My tables resembles this:

*Group*     *Refered Cases*
4H BOSS                 0
4H BSG                  0
4H SALES AND MKTG       0
ACCOUNTS RECEIVABLE     0
ASSET MANAGEMENT        0
AUDIT                   0
BOSS                    0
CORPORATE BSG           0
CUSTOMER SUPPORT        0
NETWORK ENGINEERING     0
PRODUCTION ENGINEERING  0
PRODUCTION OPERATIONS   0
SECURITY                0
SNFAL PRODUCT TEAM      0
VOICE SERVICES          0
XEROX                   0

ANSWER:

Ok, I was able to use the following code to dynamically find the last cell of the first column and input “TOTAL” into the cell and also format it accordingly.

Dim lTotalRows As Long, lTotalCols As Long
    lTotalRows = xlSheet.UsedRange.Rows.Count
    lTotalCols = xlSheet.UsedRange.Columns.Count

With xlSheet.Range("A" & (lTotalRows + 1).ToString) 'Dynamically finds the last cell of the first column, and sets it equal to "Total" and formats the cell
    .Value = "TOTAL"
    .Interior.ColorIndex = 41 'Cell Background Changed to Black
    .Columns("A:B").EntireColumn.AutoFit()
    With .Font
        .ColorIndex = 2 'Cell Font Changed to White
        .Bold = True
        .Underline = Excel.XlUnderlineStyle.xlUnderlineStyleSingle
    End With
End With

I was able to use the following code to set the last cell of the second column equal to the sum of all of all cells of the second column.

Dim totals as Integer
For Each dr As DataRow In dt.Rows
    totals += dr.Item(1)
Next

xlSheet.Range("B" & (lTotalRows + 1).ToString).Value = totals
  • 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-05T09:25:16+00:00Added an answer on June 5, 2026 at 9:25 am

    If you know the number of total rows, you could insert the formula below into the cell at the bottom of the column. Your example data shows 16 rows, not including the top header row.

    =SUM(INDIRECT(ADDRESS(ROW()-16,COLUMN())):INDIRECT(ADDRESS(ROW()-1,COLUMN())))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an Excel spreadsheet that will sit out on a network share drive.
I have an excel spreadsheet that has two columns. When I choose to save
I have an application in turbogears that dynamically generates an excel spreadsheet, meaning it
i have an excel spreadsheet that is about 300,000 rows and about 100 columns
I have an excel spreadsheet that has 2 columns. Something like this |ColA |
I have created a macro enabled Excel Spreadsheet that will programmatically load a image
i have existing code that generates a spreadsheet from excel using OpenXML. It works
I have an Excel spreadsheet that needs to display data from our SQL database.
I have a script that pulls data out of an excel spreadsheet using the
I have a C# method, see code below, that generates an Excel spreadsheet using

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.