[vba]excel中求选中数据和为给定数所有的组合
昨天下午开始学习的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中求选中数据和为给定数所有的组合的更多相关文章
- 将excel中某列数据中,含有指定字符串的记录取出,并生成用这个字符串命名的txt文件
Python 一大重要的功能,就是可处理大量数据,那分不开的即是使用Excel表格了,这里我做下学习之后的总结,望对我,及广大同仁们是一个帮助Python处理Excel数据需要用到2个库:xlwt 和 ...
- java程序转换excel中科学记数法的数据为date类型
今天出于某些原因从mongodb数据库中导出了一些数据,为了更直观的发送给其他人查阅,便使用mongoVUE的导出为excel功能. 但是导出后出现了一个问题,里边有一列存储时间的,存储的是lon ...
- Excel: 使用Countif函数来去掉Excel中重复的数据
如果使用Ruby脚本,uniq函数就能搞定一切.不过我们现在还是讨论怎么用excel的Countif函数吧. 假设Excel中有一列数据:
- 接口测试中读取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 ('小') ...
- VBS读取txt文档数据查找Excel中单元格数据符合条件的剪切到工作表2中
Dim fso,f,a set oExcel = CreateObject( "Excel.Application" ) oExcel.Visible = false '4) 打开 ...
- VBA Excel 对比两列数据
Sub Md() ' ' Macro1 Macro ' 宏由 BX 录制,时间: 2012-6-8 ' 宏中的列数可以输入 A - IV 也可以输入 1-256 ' Dim i%, j%, i1%, ...
- Excel 中批量处理数据(改成 json 格式)
如下excel: 需要处理成下面的效果: 方法: 在 C2 中输入公式: ="{"""&"code"&"" ...
- python - requests从excel中获取测试用例数据
HttpRequests.py #-*- coding:utf-8 -*- import requests class HttpRequests(): def http_requests(self,u ...
- VBA excel中表示列的字母换成数字
出自这里 数字转列标: Split(Cells(1,).Address(1,0),"$")(0) '将1-256替换红色的1就可以 Cells(1, a) 选中对应的第一行第 ...
随机推荐
- Hadoop中的辅助类ToolRunner和Configured的用法详解
在开始学习hadoop时,最痛苦的一件事就是难以理解所写程序的执行过程,让我们先来看这个实例,这个测试类ToolRunnerTest继承Configured的基础上实现了Tool接口,下面对其用到的基 ...
- jquery对象和js对象,以及它们的互相转换
jq对象无法使用DOM对象的方法,互相都不能用 ***jq对象转换成DOM对象的2中方法 1.$('div')[0下标]:jq对象是类似数组对象有长度,所以可以通过下标查找到它的DOM对象 2.$(' ...
- NetBeans平台中调用状态栏
http://blog.csdn.net/mycsoft/article/details/2326386 StatusDisplayer stD = StatusDisplayer.getDefaul ...
- Linux下的sed流编辑器命令详解
sed是stream editor的简称,也就是流编辑器.它一次处理一行内容,处理时,把当前处理的行存储在临时缓冲区中,称为“模式空间”(pattern space),接着用sed命令处理缓冲区中的内 ...
- linux下find查找命令用法
Linux下find命令在目录结构中搜索文件,并执行指定的操作.Linux下find命令提供了相当多的查找条件,功能很强大.由于find具有强大的功能,所以它的选项也很多,其中大部分选项都值得我们花时 ...
- 未能加载文件或程序集“Oracle.DataAccess, Version=2.112.1.0, Culture=neutral, PublicKeyToken=89b483f429c47342”或它的某一个依赖项。 解决方法
webconfig文件对于oracle的映射错误.需要在以下位置修改 <runtime> <legacyCorruptedStateExceptionsPolicy enabled= ...
- POJ2947Widget Factory(高斯消元解同模方程)
http://poj.org/problem?id=2947 题目大意:有n 种装饰物,m 个已知条件,每个已知条件的描述如下:p start enda1,a2......ap (1<=ai&l ...
- Tomcat 系统架构与设计模式,第 1 部分: 工作原理(转载)
简介: 这个分为两个部分的系列文章将研究 Apache Tomcat 的系统架构以及其运用的很多经典设计模式.本文是第 1 部分,将主要从 Tomcat 如何分发请求.如何处理多用户同时请求,还有它的 ...
- Odoo的Domain (一)
Odoo 的Domain:多个条件的列表. 条件:(字段名,操作符,值)三元式(列表或者元组) 字段名:当前模型的字段或者是通过点操作符访问的Many2one/Many2Many对象,当是Many2M ...
- NodeJs使用Mysql模块实现事务处理
依赖模块: 1. mysql:https://github.com/felixge/node-mysql npm install mysql --save 2. async:https://githu ...