[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) 选中对应的第一行第 ...
随机推荐
- Srum框架
Srum包括三个角色.四个会议.及三个产出物,如下图所示:
- gcc命令行详解
介绍] ----------------------------------------- 常见用法: GCC 选项 GCC 有超过100个的编译选项可用. 这些选项中的许多你可能永远都不会用到, 但 ...
- Camel In Action 阅读笔记 第一部分概述 + 第一章概述 认识Camel
第一部分: 最开始的一小步 Apache Camel 是一个开源集成框架,其目的是让系统集成变得更加简便,在本书的第一章中,我们会为您介绍它并向您展示它是如何在大型企业应用中做好集成工作.您也会了解到 ...
- rm 注意
软连接ln -s lnfile file rm -rf lnfile只是删除lnfile ln -s lndir dir rm -rf lndir 删除链接 rm -rf lndir/删除目录下文件
- leetcode@ [273] Integer to English Words (String & Math)
https://leetcode.com/problems/integer-to-english-words/ Convert a non-negative integer to its englis ...
- 了解shell
1. shell 脚本文件第一行: #!/bin/sh 或 #!/bin/bash "#!" 又称为纪数,在执行bash脚本的时候,内核会根据它来确定该用哪个程序来解释脚本 ...
- 加固Samba安全三法
欢迎大家给我投票: http://2010blog.51cto.com/350944 650) this.width=650;" onclick='window.open("htt ...
- 2d网络游戏的延迟补偿(Lag compensation with networked 2D games)
http://gamedev.stackexchange.com/questions/6645/lag-compensation-with-networked-2d-games ——————————— ...
- python 加密解密
1. 使用base64 s1 = base64.encodestring('hello world') s2 = base64.decodestring(s1) print s1, s2 结果 1 2 ...
- Python基础-函数(function)
这里我们看看Python中函数定义的语法,函数的局部变量,函数的参数,Python中函数的形参可以有默认值,参数的传递是赋值操作,在函数调用时,可以对实参进行打包和解包 1,函数定义 关键字def引 ...