Hi,
I have a spreadsheet looks like this: -
QID C1 C2 C3 C4 %a %b %c %d
-
13123 b b b b 0% 100% 0% 0%
-
13124 d d d d 0% 0% 0% 100%
-
13125 d d d d 0% 0% 0% 100%
QID is the question ID and C1 to C4 are the answers by students. Column "%a" is the percentage of "a" answered by students. I use countif function to calculate that.
Everytime I copy and paste a group of answers the number of questions ( number of rows) and number of answers (number of columns) will be different.
Is there any macro that will calculate (%a, %b, %c and %d) and insert the result in the first empty column?
Hope this is clear enough. Any answer will be appreciated!!
Thanks a lot!!!
3 1397
...
Everytime I copy and paste a group of answers the number of questions ( number of rows) and number of answers (number of columns) will be different.
Is there any macro that will calculate (%a, %b, %c and %d) and insert the result in the first empty column?
...
Thanks a lot!!!
well there's for sure a macro that does that, the problem is to make it. Why dont you give it a try by yourself and answer a little bit more specific questions.
Use a couple of DO or FOR, use CELLS, may be writing the range into a variant should be good...
Check this little example, I hope it'll help you to figure out how to do what you want. - dim i as long
-
dim dou1 as double
-
dim a
-
a = range(cells(2,2), cells(2,2).end(-4121))
-
-
for i = lbound(a) to ubound(a)
-
dou1=dou1+a(i,1)
-
next
-
i=1
-
do
-
i=i+1
-
loop until cells(2,i)=""
-
-
cells(1,1)=dou1 / (ubound(a)-lbound(a)+1)
-
well there's for sure a macro that does that, the problem is to make it. Why dont you give it a try by yourself and answer a little bit more specific questions.
Use a couple of DO or FOR, use CELLS, may be writing the range into a variant should be good...
Check this little example, I hope it'll help you to figure out how to do what you want. - dim i as long
-
dim dou1 as double
-
dim a
-
a = range(cells(2,2), cells(2,2).end(-4121))
-
-
for i = lbound(a) to ubound(a)
-
dou1=dou1+a(i,1)
-
next
-
i=1
-
do
-
i=i+1
-
loop until cells(2,i)=""
-
-
cells(1,1)=dou1 / (ubound(a)-lbound(a)+1)
-
Thanks for reply.
I use the following macro trying to insert the formula but it wont allow me.
Is there anything wrong? - Sub InsertFomula()
-
Set r = ActiveSheet.UsedRange
-
'Dim COUNTA As Integer
-
nLastRow = r.Rows.Count + r.Row - 1
-
nLastColumn = r.Columns.Count + r.Column - 1
-
For i = 1 To nLastColumn
-
For j = 1 To nLastRow
-
If Cells(1, i).Value <> "*" Then
-
Cells(1, nLastColumn + 1).Formula = "=countif(Cells(1, nLastColumn + 1),"a"/nLastColumn"
-
Selection.AutoFill Destination:=Cells(1, nLastColumn + 1), Type:=xlFillDefault'
-
Cells(1, nLastColumn + 1).Select
-
End If
-
Next
-
Next
-
End Sub
Thanks for reply.
I use the following macro trying to insert the formula but it wont allow me.
Is there anything wrong?
first of all, the cells you're changing have nothing to do with the range you defined. you're just changing cells on the active sheet. (i dont know if that's what you wanted)
And the formula you're writing has a few mistakes. try using FormulaRC instead.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: nikhil kumar |
last post by:
Hi all
i am trying to develop a macro.
the scenario is as follows,,
we have 2 sheets 1 and 2.
i want to apply a vlookup in sheet 1 and the lookup table is in sheet 2.
but in sheet 1...
|
by: =?Utf-8?B?TGV0emRvXzF0?= |
last post by:
I'd like to create a Macro that will sort some raw data, apprx 20k lines,
remove some lines based upon a condition in a certain column. Then copy this
data into a new spreadsheet and sort the ...
|
by: tonyP |
last post by:
I am very Experiences in Excel but very new to VBA & I am struggling to convert an old XLM macro into Visual Basic
The Macro helps you to compile the INDEX/MATCH formula (very similar to Vlookup...
|
by: bcr123 |
last post by:
If someone could please help with the following:
I have formula =COUNTIF(D3:D957, ">0") in cell N957 - If I copy/paste it N957 cell to empty N958 cell I get formula =COUNTIF(D4:D958, ">0").
...
|
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: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |