源数据如图:

宏操作:

生成数据后:

关键操作:在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批量插入的更多相关文章

  1. 在Redis集群中使用pipeline批量插入

    在Redis集群中使用pipeline批量插入 由于项目中需要使用批量插入功能, 所以在网上查找到了Redis 批量插入可以使用pipeline来高效的插入, 示例代码如下: Pipeline p = ...

  2. SQL SERVER 使用BULK Insert将txt文件中的数据批量插入表中(1)

    1/首先建立数据表 CREATE TABLE BasicMsg( RecvTime FLOAT NOT NULL , --接收时间,不存在时间相同的数据 AA INT NOT NULL, --24位地 ...

  3. PHP如何将多维数组中的数据批量插入数据库?

    PHP将多维数组中的数据批量插入到数据库中,顾名思义,需要用循环来插入. 1.循环insert into 语句,逐渐查询 <?php /* www.qSyz.net */ @mysql_conn ...

  4. SqlBulkCopy将DataTable中的数据批量插入数据库中

    #region 使用SqlBulkCopy将DataTable中的数据批量插入数据库中 /// <summary> /// 注意:DataTable中的列需要与数据库表中的列完全一致.// ...

  5. 多线程查询数据,将结果存入到redis中,最后批量从redis中取数据批量插入数据库中【我】

    多线程查询数据,将结果存入到redis中,最后批量从redis中取数据批量插入数据库中 package com.xxx.xx.reve.service; import java.util.ArrayL ...

  6. list转datatable,SqlBulkCopy将DataTable中的数据批量插入数据库

    /// <summary> /// 将泛类型集合List类转换成DataTable /// </summary> /// <param name="list&q ...

  7. 将Excel中的数据批量导入数据库表

    private boolean import_to_database(String excel_path) throws BiffException, IOException, HsException ...

  8. sql 中的Bulk和C# 中的SqlBulkCopy批量插入数据 ( 回顾 and 粗谈 )

    通常,我们会对于一个文本文件数据导入到数据库中,不多说,上代码. 首先,表结构如下.   其次,在我当前D盘中有个文本文件名为2.txt的文件. 在数据库中,可以这样通过一句代码插入. Bulk in ...

  9. python中pymysql executemany 批量插入数据

    import pymysqlimport timedb = pymysql.connect("IP","username","password&quo ...

随机推荐

  1. 13树莓派手动安装Home Assistant

    2017-09-05 00:53:02 https://home-assistant.io/docs/installation/raspberry-pi/ 已经安装步骤安装了带桌面的树莓派系统,在SD ...

  2. jquery第一篇

    1  jquery是什么 <1> jQuery由美国人John Resig创建,至今已吸引了来自世界各地的众多 javascript高手加入其team. <2>jQuery是继 ...

  3. angular.isArray()

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  4. CSS 使用absolute 是<div>居中

    <style>        .col-center-block {            position: absolute;            top: 50%;         ...

  5. 问题:怎么把mysql的系统时间调整为电脑的时间?(已解决)

    我的mysql是5.7版本. 浏览mysql的错误日志的时候,发现时间和电脑时间不一致. 查了一下,知道这个时间和log_timestamps有关, 就在mysql里执行下面一句话: SET GLOB ...

  6. python语法_集合

    集合:不同的元素(不可hash)组合在一起的就叫做集合,去掉重复的,以空字符返回,无序的 可以分为可变集合和不可变集合(frozenset) 创建: s = set('gm gyx') print(s ...

  7. day 24 二十四、组合、继承、方法重写和重用、super()

    一.组合 1.定义:自定义类的对象作为类的属性 A类的对象具备某一个属性,该属性的值是B类的对象 基于这种方式就把A类与B类组合到一起 对象既能使用A类中的数据与功能,也能使用B类中的数据与功能 2. ...

  8. linux --- Ansible篇

    ansible背景 1.什么是ansible? ansible是新出现的自动化运维工具,基于Python开发,集合了众多运维工具(puppet.cfengine.chef.func.fabric)的优 ...

  9. Ubuntu-1604-LTS在虚拟机设置分辨率

    在虚拟机中安装ubuntu系统时,有时系统的界面并不同虚拟机展示的匹配,需要我们进行调整.不用那么多废话,直接看图:

  10. MySQL8.0.15的安装与配置---win10

    1.下载地址 https://dev.mysql.com/downloads/installer/ 安装文件:mysql-installer-community-8.0.15.0.msi 2.安装 默 ...