昨天下午开始学习的vba,累死了,肯定有bug,待调试

vba程序如下:

 Dim aSum As Integer
Dim tSum As Integer
Dim judge() As Integer
Dim arrMax As Integer
Dim arr
Dim location() As Integer Function Test()
Dim arrWmax As Integer
Dim Rng As Range
Dim beginRow As Integer
Dim beginLine As Integer Set Rng = Application.InputBox(prompt:="Please Select....", Type:=)
rr = Rng.Address
beginRow = Rng.Column
beginLine = Rng.Row arr = Range(rr)
aSum =
arrMax = UBound(arr)
arrWmax = UBound(arr, ) For loca = To arrMax
location(loca) = beginLine
beginLine = beginLine +
Next For col = To arrWmax 'modify
tSum = arr(, col)
Call subTest(, beginRow)
Next End Function Function subTest(n As Integer, beginRow As Integer)
If aSum > tSum Then
Exit Function
End If Dim i As Integer
Dim j As Integer
If aSum = tSum Then
For i = To n
If judge(i) = Then
Sheets().Cells(location(i), beginRow).Interior.Color = vbRed
End If
Next Exit Function
End If If n = arrMax Then
Exit Function
End If For j = n To arrMax
If judge(j) = Then
judge(j) =
aSum = aSum + arr(j, )
Call subTest(j, beginRow) judge(j) =
aSum = aSum - arr(j, )
If j < arrMax Then
While arr(j, ) = arr(j + , )
j = j +
Wend
End If
End If
Next End Function

[vba]excel中求选中数据和为给定数所有的组合的更多相关文章

  1. 将excel中某列数据中,含有指定字符串的记录取出,并生成用这个字符串命名的txt文件

    Python 一大重要的功能,就是可处理大量数据,那分不开的即是使用Excel表格了,这里我做下学习之后的总结,望对我,及广大同仁们是一个帮助Python处理Excel数据需要用到2个库:xlwt 和 ...

  2. java程序转换excel中科学记数法的数据为date类型

    今天出于某些原因从mongodb数据库中导出了一些数据,为了更直观的发送给其他人查阅,便使用mongoVUE的导出为excel功能.   但是导出后出现了一个问题,里边有一列存储时间的,存储的是lon ...

  3. Excel: 使用Countif函数来去掉Excel中重复的数据

    如果使用Ruby脚本,uniq函数就能搞定一切.不过我们现在还是讨论怎么用excel的Countif函数吧. 假设Excel中有一列数据:

  4. 接口测试中读取excel中的请求数据含有中文问题,UnicodeEncodeError: 'latin-1' codec can't encode character '\u5c0f' in position

    错误信息:UnicodeEncodeError: 'latin-1' codec can't encode character '\u5c0f' in position 31: Body ('小') ...

  5. VBS读取txt文档数据查找Excel中单元格数据符合条件的剪切到工作表2中

    Dim fso,f,a set oExcel = CreateObject( "Excel.Application" ) oExcel.Visible = false '4) 打开 ...

  6. VBA Excel 对比两列数据

    Sub Md() ' ' Macro1 Macro ' 宏由 BX 录制,时间: 2012-6-8 ' 宏中的列数可以输入 A - IV 也可以输入 1-256 ' Dim i%, j%, i1%, ...

  7. Excel 中批量处理数据(改成 json 格式)

    如下excel: 需要处理成下面的效果: 方法: 在 C2 中输入公式: ="{"""&"code"&"" ...

  8. python - requests从excel中获取测试用例数据

    HttpRequests.py #-*- coding:utf-8 -*- import requests class HttpRequests(): def http_requests(self,u ...

  9. VBA excel中表示列的字母换成数字

    出自这里 数字转列标: Split(Cells(1,).Address(1,0),"$")(0)    '将1-256替换红色的1就可以 Cells(1, a) 选中对应的第一行第 ...

随机推荐

  1. POJ 2395 Out of Hay(MST)

    [题目链接]http://poj.org/problem?id=2395 [解题思路]找最小生成树中权值最大的那条边输出,模板过的,出现了几个问题,开的数据不够大导致运行错误,第一次用模板,理解得不够 ...

  2. c#装B指南

    要想让自己的代码,看起来更优雅,更有逼格,更高大上,就一定要写出晦涩难懂,而又简洁的代码来. 对于类自身的全局变量,一定要加this,对于基类的,一定要加base.反射不要多,但一定要有,而且偶尔就来 ...

  3. Vmware虚拟机的网络设置

    设置宿主机器的Vmnat8网络适配器. 设置IP地址如图所示 设置虚拟机的的网络 选择NAT方式 启动虚拟机,设置虚拟机的网络适配器

  4. SA

    hdu 4029 题意:给你一个字符矩阵,统计不同的子矩阵的个数: 分析:枚举子矩阵的宽度w,对于每一个w,将每一行长度可以是w的字符串HASH成一个值,然后用map标记,因为宽确定了,hash完之后 ...

  5. POJ 3449 Geometric Shapes(判断几个不同图形的相交,线段相交判断)

    Geometric Shapes Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 1243   Accepted: 524 D ...

  6. python知识点(07-08)

    python: 循环else: while true: if x>1: print() break else: print() 文件循环: for line in open(‘test.txt’ ...

  7. TQImport3XLS.Map

    property Map: TStrings; 设置数据集字段和Excel单元格之间定义映射属性以下列方式: FieldName=CellRange 导入单独的单元格 Field1=A1 Field1 ...

  8. UVaLive 6693 Flow Game (计算几何,线段相交)

    题意:给个棋盘,你可以在棋盘的边缘处放2个蓝色棋子2个黄色棋子,问连接2组同色棋子的最小代价,如果线路交叉,输-1. 析:交叉么,可以把它们看成是两条线段,然后如果相交就是不行的,但是有几种特殊情况, ...

  9. Regular Expression--Good parts

    匹配URL的正则表达式 <!doctype html><html lang="en"><head> <meta charset=" ...

  10. 使用Vagrant在Windows下部署开发环境

    做Web开发少不了要在本地搭建好开发环境,虽然说目前各种脚本都有对应的Windows版,甚至是一键安装包,但很多时候和Windows环境的相性并不是那么好,各麻烦的问题是实际部署的环境通常是Linux ...