当前位置: 动力学知识库 > 问答 > 编程问答 >

excel vba - Vba program in average

问题描述:

I would like an help on vba since I never worked nor have any experience in programming and needed it to analyze a huge amount of data.

I have 3 columns,

  • A is time
  • B is positions
  • C is pulses (image)

What I really want is to obtain in another cells (like range.value) the average of the positions that are obtained with 0 pulse and then go to 80 pulse and do the same and then go to the next 0 and do the same, and so on...

Is it possible to obtain also the value of time at which the pulse 80 occurs in each case?

Thank you!

M

网友答案:

I do not understand what you seek. I think I understand something about the data but not enough to guess what you want done with it.

However, if someone did understand what you seek, I do not believe they would help much by writing a macro for you. It might solve today's problem but you would not be ready for tomorrow's problem.

You must learn VBA. Search the internet for "Excel VBA Tutorial". There are many; some good some less good. Try a few and see which fits your learning style. Alternatively visit a good bookshop or library and select an Excel BVA Primer. Again many to chose from. The advantage of a library is you can take a couple home to try before buying the one you prefer. I like to have reference books on my shelf so that was my approach.

It will not take long to master the basics and that investment in study will quickly repay itself. I believe you will have real trouble understanding any bits of useful code you find here or elsewhere without knowing the basics.

You will have to design your program yourself. My guess from your description is that your data looks like:

Time  Positions  Pulses
xxxx  yyyy         0
xxxx  yyyy        10
xxxx  yyyy        50
xxxx  yyyy        80
xxxx  yyyy         0
xxxx  yyyy        20
xxxx  yyyy        60
xxxx  yyyy        80
xxxx  yyyy         0
xxxx  yyyy        30
xxxx  yyyy        40
xxxx  yyyy        50
xxxx  yyyy        80

You do not tell us about the format or contents of the Time and Position columns. I believe you have a number of sub-tables with the first row having 0 Pulses and the last row having 80 pulses. You do not tell us if there are a fixed or variable number of rows per sub-table.

If a fixed number of rows per sub-table, a simple For-Next loop will be sufficient:

Const RowsPerSubTable As Long = 5
Dim RowStart As Long
Dim RowEnd As Long
Dim RowLast As Long

For RowStart = 2 To RowLast Step RowsPerSubTable
  RowEnd = RowStart + RowsPerSubTable - 1

  ' Process sub-table RowStart to RowEnd

Next

With a variable number of rows per sub-table you will have to search for the 80 pulses row. That will be a little more complicated but not much.

The above is very basic VBA. Any tutorial or primer will introduce For-Next loops at an early stage.

I hope the above convinces you that your requirement is not difficult to achieve and that with a little study you can do most of the programming yourself.

If you have a problem, come back with your code and explain why it is not working as you wish. That is the type of question this site specialises in.

分享给朋友:
您可能感兴趣的文章:
随机阅读: