开发宏功能:excel中从sheet批量插入
源数据如图:


宏操作:


生成数据后:


关键操作:在excel中启用开发工具,添加宏,然后添加模块即可,编辑完代码后,自定义功能按钮即可.
Sub MakeDataSource() Dim isExistDestinationSheet
isExistDestinationSheet = False Dim i For i = 1 To Sheets.Count
If Sheets(i).Name = "b" Then
isExistDestinationSheet = True
End If
Next If Not isExistDestinationSheet Then
If MsgBox("目标表不存在,将自动建Sheet:b", vbOKCancel) = vbOK Then
Sheets.Add after:=ActiveSheet
ActiveSheet.Name = "b"
Sheets("b").Select
ThisWorkbook.Worksheets("b").Range("a1") = "分类列表"
ThisWorkbook.Worksheets("b").Range("b1") = "名称列表"
ThisWorkbook.Worksheets("b").Range("c1") = "规格列表"
ThisWorkbook.Worksheets("b").Range("d1") = "添加时间"
ThisWorkbook.Worksheets("b").Rows(1).Font.Bold = True
ThisWorkbook.Worksheets("b").Rows(1).HorizontalAlignment = xlCenter
ThisWorkbook.Worksheets("b").Columns("d").NumberFormatLocal = "YYYY-MM-DD HH:MM:SS" End If
End If '复制插入
Dim iMinimumDestination, iMinimumSource
iMinimumDestination = ThisWorkbook.Worksheets("b").UsedRange.Rows.Count + 1
iMinimumSource = 2
If Len(Worksheets("a").Range("f3")) <> 0 Then For i = iMinimumSource To iMinimumSource + 11
If Len(ThisWorkbook.Worksheets("a").Columns("a").Rows(i).Value) <> 0 Then
ThisWorkbook.Worksheets("b").Columns("a").Rows(iMinimumDestination).Value = Worksheets("a").Range("f3")
ThisWorkbook.Worksheets("b").Columns("b").Rows(iMinimumDestination).Value = ThisWorkbook.Worksheets("a").Columns("a").Rows(i).Value
ThisWorkbook.Worksheets("b").Columns("c").Rows(iMinimumDestination).Value = ThisWorkbook.Worksheets("a").Columns("b").Rows(i).Value
ThisWorkbook.Worksheets("b").Columns("d").Rows(iMinimumDestination).Value = Now
iMinimumDestination = iMinimumDestination + 1
End If
Next
End If
End Sub
开发宏功能:excel中从sheet批量插入的更多相关文章
- 在Redis集群中使用pipeline批量插入
在Redis集群中使用pipeline批量插入 由于项目中需要使用批量插入功能, 所以在网上查找到了Redis 批量插入可以使用pipeline来高效的插入, 示例代码如下: Pipeline p = ...
- SQL SERVER 使用BULK Insert将txt文件中的数据批量插入表中(1)
1/首先建立数据表 CREATE TABLE BasicMsg( RecvTime FLOAT NOT NULL , --接收时间,不存在时间相同的数据 AA INT NOT NULL, --24位地 ...
- PHP如何将多维数组中的数据批量插入数据库?
PHP将多维数组中的数据批量插入到数据库中,顾名思义,需要用循环来插入. 1.循环insert into 语句,逐渐查询 <?php /* www.qSyz.net */ @mysql_conn ...
- SqlBulkCopy将DataTable中的数据批量插入数据库中
#region 使用SqlBulkCopy将DataTable中的数据批量插入数据库中 /// <summary> /// 注意:DataTable中的列需要与数据库表中的列完全一致.// ...
- 多线程查询数据,将结果存入到redis中,最后批量从redis中取数据批量插入数据库中【我】
多线程查询数据,将结果存入到redis中,最后批量从redis中取数据批量插入数据库中 package com.xxx.xx.reve.service; import java.util.ArrayL ...
- list转datatable,SqlBulkCopy将DataTable中的数据批量插入数据库
/// <summary> /// 将泛类型集合List类转换成DataTable /// </summary> /// <param name="list&q ...
- 将Excel中的数据批量导入数据库表
private boolean import_to_database(String excel_path) throws BiffException, IOException, HsException ...
- sql 中的Bulk和C# 中的SqlBulkCopy批量插入数据 ( 回顾 and 粗谈 )
通常,我们会对于一个文本文件数据导入到数据库中,不多说,上代码. 首先,表结构如下. 其次,在我当前D盘中有个文本文件名为2.txt的文件. 在数据库中,可以这样通过一句代码插入. Bulk in ...
- python中pymysql executemany 批量插入数据
import pymysqlimport timedb = pymysql.connect("IP","username","password&quo ...
随机推荐
- Promise和setTimeout执行顺序 面试题
看到过下面这样一道题: (function test() { setTimeout(function() {console.log(4)}, 0); new Promise(function exec ...
- 2019-2-21.NET中异常类(Exception)
.NET中异常类(Exception) 异常:程序在运行期间发生的错误.异常对象就是封装这些错误的对象. try{}catch{}是非常重要的,捕获try程序块中所有发生的异常,如果没有捕获异常的话, ...
- 使用CSS达到文字首尾对齐效果
在制作表单的时候经常会遇到需要不同个数的文字首尾对齐,比如: <span>姓名:</span> <span>联系方式:</span> 姓名: 联系方式: ...
- Python字符串的相关操作
1.大小写转换 判断字符串 s.isalnum() #所有字符都是数字或者字母 s.isalpha() #所有字符都是字母 s.isdigit() #所有字符都是数字 s.islower() #所有字 ...
- [LeetCode] Find Eventual Safe States 找到最终的安全状态
In a directed graph, we start at some node and every turn, walk along a directed edge of the graph. ...
- puppeteer 填充基础表单
main.js const pptr = require("puppeteer"); const gotoUrl = "http://127.0.0.1:5500/ind ...
- Linux下查找某一文件常用的方式
当我们需要在ubuntu中找到之前的某一个文件,该用什么方式呢?用以下命令你就可以快速定位: find / -name "pycharm.sh" 用find查找这个命令,确定查找范 ...
- ping vs telnet, what is the difference between them and when to use which?
Ping is an ICMP protocol. Basically any system with TCP/IP could respond to ICMP calls if they were ...
- Codeforces Round #542 题解
Codeforces Round #542 abstract I决策中的独立性, II联通块染色板子 IIIVoronoi diagram O(N^2 logN) VI环上距离分类讨论加取模,最值中的 ...
- [dev][dpdk][crypto] dpdk加解密设备与IPSEC
概述 分三部分,加解密框架(crypto framework),加解密设备(crypto dev),安全协议(Security Framework) × API,设计思路等,都在加解密框架里:见文档 ...