Hi,
I'm trying to sum each column and each row of a datagrid and put the totals of columns at the bottom of each column and totals of row at the last empty column.
How do I do this?
I found the following at some MS site but it doesn't put the results anywhere that I can see.
Thank you so much in advance!!!!
Linda -
Sub TotalRowsAndColumns()
-
' This macro assumes that you have selected any cell or group of
-
' cells within a rectangular region of cells that you would like to
-
' have totaled. The totals will appear in the row below and the
-
' column to the right of the current region.
-
Dim r As Integer
-
Dim c As Integer
-
Dim i As Integer
-
Dim j As Integer
-
Dim myArray As Variant
-
' Declaring myArray as a Variant prepares it to receive a range of
-
' cells. At that point it is transformed automatically into an array
-
' with beginning subscript myArray(1,1).
-
'Refer to the region surrounding the current selection
-
With Selection.CurrentRegion
-
r = .Rows.Count
-
c = .Columns.Count
-
'resize for totals row and column and place into array
-
myArray = .Resize(r + 1, c + 1)
-
' The following 10 lines of macro code (including comments)
-
' are what is commonly referred to
-
' as a Nested Loop. The variable i keeps track of the row number,
-
' while j keeps track of the column number. Every time j cycles
-
' through the available columns, i gets incremented by one and j
-
' starts the cycle from one to c all over again.
-
For i = 1 To r
-
For j = 1 To c
-
'total for row i
-
myArray(i, c + 1) = myArray(i, c + 1) + myArray(i, j)
-
'total for column j
-
myArray(r + 1, j) = myArray(r + 1, j) + myArray(i, j)
-
'grand total
-
myArray(r + 1, c + 1) = myArray(r + 1, c + 1) + myArray(i, j)
-
Next j
-
Next i
-
' Return the array, which now contains an extra row and column
-
' for the totals, to the worksheet.
-
.Resize(r + 1, c + 1) = myArray
-
End With
-
End Sub
-
2 1161
How about this: -
With MSHFlexGrid1
-
For iCol = 0 To MSHFlexGrid1.Cols - 1
-
If iCol = 1 Then
-
mstTitle = .TextMatrix(iRow, iCol)
-
End If
-
If iCol = 2 Then
-
mstDescription = .TextMatrix(iRow, iCol)
-
End If
-
If iCol = 3 Then
-
mstRecordID = .TextMatrix(iRow, iCol)
-
GetRecordID
-
End If
-
stColumnHeader = MSHFlexGrid1.ColHeaderCaption(0, iCol) & ": "
-
stDisplayText = stDisplayText & stColumnHeader & .TextMatrix(iRow, iCol) & vbCrLf & vbCrLf
-
Next
-
End With
-
Try that, please write if not helpful, Linda...
Good luck with the project!
Hi Dokoll,
What abt the function GetRecordID?
I don't have that....
So sorry but I also don't understand the codes so not sure how to Dim the variables.
Can you plse be more specific? I'm dumber than a newbie....
Thanks much and have a super weekend!!!
linda
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Jordan O'Hare |
last post by:
Hello Everyone,
I am after some help with the following:
I have a windows application that contains a list box and
two data grids. All three controls are binded to a dataset
that contains...
|
by: kk |
last post by:
Have 2 problems, any help is appreciated.
Tab with Grids
--------------
BL - fetching data from DB ( 5 secs - 10 rows)
Grid Laod - 20 secs
Grid Paint on tab change - 20 secs
Problem: The...
|
by: pmud |
last post by:
Hi,
I need to display columns in a data grid based on 7 different queries. Now I
have 32 questions:
1. Is it possble to have 1 single data adapter with 7 queries & 1 data set
or do I need to...
|
by: Josef Meile |
last post by:
Hi,
I'm using a ComboBox, some Textboxes, and a DataGrid to represent a
many-to-many relationship between Person and Course. Each time that I change
the value in the ComboBox (which for now is...
|
by: Hutty |
last post by:
I've looked around and have yet to find anything that would answer my
question regarding formating a column in a datagrid. My grid looks like
this as far as data"
AMHQCON|51300.01|-3147
The...
|
by: pmud |
last post by:
Hi,
I have a web page (asp.net, code:c#). I havean html table with text boxes.
Based on the user input , records are displayed in the data grid below it.
Now the datagrid has a large no. of...
|
by: tshad |
last post by:
Is there a way to carry data that I have already read from the datagrid from
page to page?
I am looking at my Datagrid that I page through and when the user says get
the next page, I have to go...
|
by: Anil Gupte |
last post by:
After reading a tutorial and fiddling, I finally got this to work. I can
now put two tables created with a DataTable class into a DataRelation.
Phew! And it works!
Dim tblSliceInfo As New...
|
by: NormAmst |
last post by:
I have a list of CPU processing times and job durations for an entire department at work. There are 3 classifications I am maintaining. CPU time during peak hours , CPU time during non peak hours...
|
by: insirawali |
last post by:
Hi all,
I have this problem, i need to know is there a way i cn use the data
adapter's update method in this scenario.
i have 3 tables as below
create table table1{
id1 int identity(1,1)...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
| |