I am asked to design a report with displaying multiple cells in a row, to make better usage of the space.
For example, my query would return some thing like this:
Name Count
n1 2
n2 3
n3 4
And what I would like to display in the report is:
Name Count Name Count Name Count
n1 2 n2 3 n3 4
Is there a good way to handle that?
Thanks all
Related
I need a little help here for excel and VBA, lets says my column like this
No Name Rank Point
1 Foo 1
2 Bar 1
3 Jhon 1
4 Doe 1
i need to fill a point using adds the same rank by using index of number and then divide by the number of duplicates value, point = (1+2+3+4)/4 i need an help for using a VBA script, any of help will be appreciate
You dont need VBA for thet. If your data is from A1 to C5 (with Point in Column D), lke in your example, put the following formula in D2 and pull it down:
=SUMIF($C$2:$C$5,C2,$A$2:$A$5)/COUNTIF($C$2:$C$5,C2)
If you need VBA, just add Application.Worksheetfunction to both formula parts.
I am running into a problem in VBA in excel.
I am trying to create a participant registration program in excel for a sports tournament. One can add data like the weight, age and name of a participant. And then based on that, The participants are divided into poules named with letters A, B... until Z. I have a table which can sort these poules by letters and then for example only display the participants which are in poule A such as below
Example
Now i want to count the numbers with VBA macros of participants in the poule which is displayed by the sorted table. For example when i sort on poule A it has to return 3 and when i sort on B, it has to return 2.
Determined by the number of participants in a poule the program will print a different poule scheme, depending on the number of participants. (i have this part in VBA)
The problem is when i have a sorted table like below
Example 2
It counts all the participants, and not just the ones in B or any other sorted letter.
I have this:
Sub Count()
Dim nRows As Integer
nRows = Range(Range("A18"), Range("A18").End(xlDown)).Rows.Count
MsgBox (nRows)
End Sub
This works well if you sort A, but when you sort any other letter, it counts All the table until that letter. Eg. when you sort B, it displays 5 (Number of A + B).
I have looked on the internet for a really long time to find a solution but without succes.
I hope my question is clear and that somebody can help me.
I am assuming that you are using worksheet functions. Use Subtotal when working with filtered data.
These parameters evaluate all cells visible or hidden
1 AVERAGE
2 COUNT
3 COUNTA
4 MAX
5 MIN
6 PRODUCT
7 STDEV
8 STDEVP
9 SUM
10 VAR
11 VARP
These parameters evaluate only visible cells
101 AVERAGE
102 COUNT
103 COUNTA
104 MAX
105 MIN
106 PRODUCT
107 STDEV
108 STDEVP
109 SUM
110 VAR
111 VARP
The code does work now, except that it only counts the first letters it encounters.
So when the first column for the poules is for example A A A E A A B B E.
And i sort to A and use the count function, it only returns a value of 3 and not of 5 (because there are 5 A's)
When I sort the table to A, it looks like this (column number, poule value):
14 A
15 A
16 A
18 A
19 A
And it returns just a count of 3, have you maybe got any fixes for that problem as well?
Pictures:
sorted tabel to E
Table
Range.SpecialCells will return a range of only visible cells.
Dim rSource As Range
Dim rVisibleCells
Set rSource = Range(Range("A2"), Range("A2").End(xlDown))
Set rVisibleCells = rSource.SpecialCells(xlCellTypeVisible)
MsgBox rVisibleCells.Rows.Count
I have to apply a logical count formula on a column which contains some value. It contains identical and non-identical numbers.
What I want is a way to apply a formula to the next column which will lookup the whole column and decide on below condition:
whether A1=A2; if True, if A1=A3 and so on till it returns False (not equal value) then count all the true results in a row and reflect the value against the first cell.
Then if there was three match then it should reflect 3 against the first cell and the next two cells should be left blank. Below is the example column:
Numbers No of Days
47.76
-429.98
-429.98
-429.98
-1328.98
-1328.98
-1328.98
-833.32
-643.7
-1328.98
-580.26
-556.76
-556.76
-1181.78
-1139.99
-1124.49
-1103.59
-1103.59
-1091.39
-1048.94
-1048.94
-451.38
-451.38
-321
-321
438.5
477.5
698.76
795.93
795.93
804.83
What I want should be like below after formula:
Numbers No of Days
47.76 1
-429.98 3
-429.98
-429.98
-1328.98 3
-1328.98
-1328.98
-833.32 1
-643.7 1
-1328.98 1
-580.26 1
-556.76 2
-556.76
-1181.78 1
-1139.99 1
-1124.49 1
-1103.59 2
-1103.59
-1091.39 1
-1048.94 2
-1048.94
-451.38 2
-451.38
-321 2
-321
438.5 1
477.5 1
698.76 1
795.93 2
795.93
804.83 1
Please help guys as whatever I tried has failed here. Need some excel experts to share some advise or a resolve.
In Cell B2 use =IF(A2=A1,"",MATCH(0,--(A2=$A2:$A$50),0)-1) entered using ctrl+shift+enter
The if statement checks to see if the number is the same as the one above it and if it is it leaves the cell blank.
Inside the match statement --(A2=$A2:$A$50) returns an array of 0s (if the cell doesn't match A2) or 1s (if it does match). The match statement finds the first 0 in the array (the first number that doesn't match). Since this returns the place in the array that starts at the current row it will give the number of rows that match+1. We just need to subtract that 1 to get the number we need.
I am a beginner in vba...i am doing a task which consist of 6 sequences..
Sequence 1
Sequence 2
Sequence 3
Sequence 4
Sequence 5
Sequence 6
In sheet-1 i have done all the calculations for all 6 sequences and tabulated the results..
The order of sequence changes according to constraints...i.e, "1,2,3","1,2,4","1,3,4","1,3,5"..)...
Is it possible to pick the required sequence along with its contents(tabulated results) from sheet-1 and display it in another sheet?
(i.e., For sequence order "1,2,4",only sequences 1,2 and 4 from sheet 1 should be displayed in another sheet)
Kindly help me to solve my problem..
I would like to add more data..
In Sheet 1 i have created a table which gives the order of sequence to be followed
Input data
Enter A
Enter B
Enter C (True or False)
Constraints
If (AND(A=B,C="TRUE"),"1,2,3",IF(AND(A<>B,C="TRUE"),"1,2,4",IF(AND(A=B,C="FALSE"),"1,3,4",IF(AND((A<>B,C="FALSE"),"1,3,5",""))))
RESULT DISPLAYED
1,2,3 OR 1,2,4 OR 1,3,4 OR 1,3,5 (DEPENDING ON MY INPUT DATA)
IN SHEET 2 I HAVE DONE THE CALCULATIONS FOR ALL THE SIX SEQUENCES
SEQUENCE 1
A) VERIFICATION OF X
B) VERIFICATION OF Y
C) VERIFICATION OF Z
SEQUENCE 2
A) VERIFICATION OF P
B) VERIFICATION OF Q
C) VERIFICATION OF R
.
.
.
.
TILL SEQUENCE 6
NOW, i want to filter my sequence according to the result displayed in sheet 1
example: If the sequence displayed in sheet 1 is 1,3,4 either only these sequences should be displayed in sheet 2 or the sequences 1,3,4 selected from sheet 2 shuold be displayed in sheet 3...
I am assuming that each sequence is a formula that produces a number (if not, post some sample data). Also assuming that the number is the order you want things displayed. Assuming sample data like this in Range("A1:A4):
=D1+D2
=D3+D4
=E4+E4
=F4+F5
Values like this in Range("A1:A4"):
5
4
1
2
So the order you want is A3, A4, A2, A1. Here is the VBA code:
'Copy the data so that we can maintain the original (optional)
For i = 1 to 4
ActiveSheet.Range("B1").Offset(i-1,0).Value = ActiveSheet.Range("A1").Offset(i-1,0).Value
next i
'Sort the new data
ActiveSheet.Columns("B").Sort key1:=Range("B1"), _
order1:=xlAscending, header:=xlNo
'Copy the new sorted rows to another worksheet
For i = 1 to 4
Sheets("Sheet1").Range("A1").Offset(i-1,0).Value = ActiveSheet.Range("B1").Offset(i-1,0).Value
next i
I made a lot of assumptions, so not sure if I got it right. Posting sample data makes it easier to answer.
So I have a chart that looks something like this. Assume that the top left value, 1, is in cell A1:
x= 1 2 3 4 5 6 7 8
4 3 2 1 2 3 4 5
9 8 7 6 7 8 9 10
8 7 6 5 4 3 2 1
Sum= 21 18 15 12 13 14 15 16
There are x values from 1 to 8, and a three columns of values resulting from using it an equation or something below it. The sum is the sum of the three values below their corresponding x-value.
I'm stuck trying to figure something out that will go through the row of sums, find the smallest value, and then assign it's corresponding x-value to a variable. I also need to assign the values to the left and right of that x-value to other variables.
For this particular chart, 12 is the smallest of the sums, so I would assign variable1 = 4, since that is that column's corresponding x-value. Then my second variable, which is called lowerbound, would equal 3, since it is to the left of x = 4, and my third variable, which is called upperbound, would equal 5, since it is to the right of x = 4.
If I could get the cell address returned of the x-value that corresponds to the smallest sum, then I could assign it to a variable, and then simply offset from that cell to assign the other variables. Even if I could make a program that will return me the cell of the minimum sum value, I could offset to the x-row, and go from there.
How would I do something like that?
TL:DR: To ask more clearly, since that's a lot of words: What would a program look like that detects the smallest value in the sum row, and returns the cell address of that value?
The length of the rows are an unknown, and vary a lot, but the length of the columns are given. They do change depending on the problem, but they will always be known. So I will always know how many rows are in a column, but I will not know how many columns are in a row.
This is the most confusingly-worded thing I've ever written in my entire life, but I hope I've explained it well enough to make some sense.
You guys really are amazing, by the way. I've gotten so far on this program, and it's all because of how helpful you are. I honestly think I would still be stuck at the beginning with you guys! You're willing to tolerate a newbie's incessant questions.
I am assuming that the sum is in A4:H4. Please change as applicable
You can use a formula like
=CELL("address",INDEX(A4:H4,MATCH(MIN(A4:H4),A4:H4,0)))
If you want to use VBA then you can use this
Sub Sample()
MsgBox Application.Evaluate("=CELL(""address"",INDEX(A4:H4,MATCH(MIN(A4:H4),A4:H4,0)))")
End Sub
Using your example, the following formula returns the cell address in row 1 whose value in row 5 is the lowest:
=ADDRESS(1,MATCH(MIN(A5:H5),A5:H5,0))
And if you want that cell's value, use INDIRECT. It takes the address as a string.
=INDIRECT(ADDRESS(1,MATCH(MIN(A5:H5),A5:H5,0)))
If you sum the columns by taking the sum of the array. Here is the VBA version:
For j = 1 To 8
For i = 1 To 3
sum(j) = sum(j) + Cells(i + 1, j + 1)
Next i
Cells(5, j + 1) = sum(j)
Next j