vba excel排序_Excel VBA单击“形状以对列进行排序”

2023-10-24 05:20

本文主要是介绍vba excel排序_Excel VBA单击“形状以对列进行排序”,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

vba excel排序

People are lazy! Shocking, I know, but who wants to click twice in Excel, if you can do the same thing by only clicking once?

人们很懒! 我知道令人震惊,但是如果您只单击一次就可以做同样的事情,谁想在Excel中单击两次?

SortClick00

Dave Peterson, champion of weary Excel users, created this sample Excel VBA sort code, that adds invisible rectangles at the top of each column in a table.

疲惫的Excel用户的拥护者Dave Peterson创建了此示例Excel VBA排序代码 ,该代码在表格中每列的顶部添加了不可见的矩形。

A macro is automatically assigned to each rectangle, and it sorts the table by that column, when you click it.

宏会自动分配给每个矩形,当您单击它时,它将按该列对表格进行排序。

Two benefits of using Dave's code:

使用Dave的代码有两个好处:

  1. Reduced wear and tear on clicking fingers

    减少点击手指的磨损
  2. Less risk of table scrambling, because it ensures the entire table is selected before sorting

    减少表加扰的风险,因为它可以确保在排序之前选择了整个表
SortClick01

编辑设置宏 (Edit the Setup Macro)

There are two macros in Dave's sample file.

Dave的示例文件中有两个宏。

  • SetupOneTime - run this once, to add the hidden rectangles

    SetupOneTime-运行一次,以添加隐藏的矩形
  • SortTable - sorts table by selected column, when heading is clicked

    SortTable-单击标题时,按选定的列对表进行排序

Before you run the SetupOneTime macro, you should edit both macros, to adjust them for your workbook

在运行SetupOneTime宏之前,应编辑两个宏,以针对工作簿进行调整。

  1. On the Excel Ribbon, click the Developer tab, then click Macros

    在Excel功能区上,单击“开发人员”选项卡,然后单击“宏”
  2. Click SetupOneTime, and click Edit

    单击SetupOneTime,然后单击编辑
SortClick02

In the SetupOneTime macro, change the iCol variable to match the number of columns in your table. If your table doesn't start in cell A1, change that reference.

在SetupOneTime宏中,更改iCol变量以匹配表中的列数。 如果您的表不在单元格A1中开始,请更改该引用。

SortClick03

编辑SortTable宏 (Edit the SortTable Macro)

Next, change the variables in the SortTable macro, to suit your table settings. You can adjust:

接下来,更改SortTable宏中的变量以适合您的表设置。 您可以调整:

  • TopRow (row where headings are located)

    TopRow(标题所在的行)
  • iCol (number of columns in the table)

    iCol(表中的列数)
  • strCol (column to check for last row)

    strCol(要检查最后一行的列)
SortClick04

If you want to see the rectangle outlines, change the Line.Visible setting to True.

如果要查看矩形轮廓,请将Line.Visible设置更改为True。

SortClick06

运行SetupOneTime宏 (Run the SetupOneTime Macro)

After you've edited the macros, you can run the setup macro:

编辑宏后,可以运行setup宏:

  1. Select the sheet where your table is located.

    选择表所在的表。
  2. On the Excel Ribbon, click the Developer tab, then click Macros

    在Excel功能区上,单击“开发人员”选项卡,然后单击“宏”
  3. Click SetupOneTime, and click Run

    单击SetupOneTime,然后单击运行
SortClick07

Now, click a heading in the table, to sort by that column.

现在,单击表中的标题以按该列排序。

Excel 2007形状问题 (Excel 2007 Shapes Problem)

When I was getting this blog post ready, I discovered that Dave's original code needed a tweak before it would work correctly in Excel 2007 and Excel 2010.

当我准备好这篇博客文章时,我发现Dave的原始代码需要进行调整,然后才能在Excel 2007和Excel 2010中正常运行。

In the original code, written for Excel 2003, there was one line of code that made the rectangular shape invisible:

在为Excel 2003编写的原始代码中,有一行代码使矩形不可见:

.Fill.Visible = False

In the newer versions of Excel, only the borders of the invisible shapes were clickable, so I had to change the code to these two lines:

在较新版本的Excel中,仅可单击不可见形状的边框,因此我不得不将代码更改为以下两行:

.Fill.Solid
.Fill.Transparency = 1#

The revised code worked for me in Excel 2003, 2007 and 2010, creating transparent shapes that were clickable.

修改后的代码在Excel 2003、2007和2010中为我工作,创建了可单击的透明形状。

SortClick05

下载样本工作簿 (Download the Sample Workbook)

To see the full code for the SetupOneTime and SortTable macros, and download the sample workbook, visit the Excel VBA: Sort Data With Invisible Rectangles page on the Contextures website.

若要查看SetupOneTime和SortTable宏的完整代码,并下载示例工作簿,请访问Contextures网站上的Excel VBA:“用不可见的矩形排序数据”页。

观看单击标题以对列进行排序视频 (Watch the Click Headings to Sort Columns Video)

To see the steps for editing the code, adding the rectangles, and clicking the hidden shapes, you can watch this short Excel tutorial video.

要查看编​​辑代码,添加矩形和单击隐藏的形状的步骤,您可以观看这段简短的Excel教程视频。

演示地址

翻译自: https://contexturesblog.com/archives/2010/11/01/excel-vba-click-shape-to-sort-column/

vba excel排序


http://www.taodudu.cc/news/show-8049703.html

相关文章:

  • Excel VBA的实用功能
  • matlab round函数
  • php中round函数能给整数用吗,PHP四舍五入、取整、round函数使用示例_PHP
  • c++中round函数的用法
  • python中round函数如何使用_python中round函数如何使用
  • 怎么做好速卖通店铺?我这些年做速卖通的心得分享!
  • asure学习心得
  • web网站建设手机推荐网站
  • 关于网站建设的一点心得
  • 个人网站建设指南
  • 区县网站群建设心得
  • 网站设计的小心得
  • 高手网站建设心得
  • 网站搭建心得
  • 传说中的外挂技术-CALL是什么?游戏外挂中的找CALL
  • Spring框架概述及核心设计思想
  • 外挂制作之------游戏DLL注入
  • OD 内存断点和硬件断点 小结
  • 游戏外挂编写学习总结
  • python字符串常用操作-python中字符串(str)常用操作总结
  • python中str如何使用_python中字符串(str)常用操作总结
  • 06-Python字符串
  • DAG上动态规划——巴比伦塔问题
  • 人月神话(7)巴比伦塔为什么失败
  • 【算法竞赛入门经典例题题解】 【DP】练习城市里的间谍 A Spy in the Metro UVA1025 UVA437 巴比伦塔 刘汝佳
  • 人月神话读书笔记(7)----为什么巴比伦塔会失败
  • 微服务化实战案例分析
  • [转载][工具]Java自然语言处理 LingPipe
  • 网盘搜索聚集工具Python转exe
  • 2023 Yiso搜索引擎PHP开源源码 无需数据库
  • 这篇关于vba excel排序_Excel VBA单击“形状以对列进行排序”的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



    http://www.chinasem.cn/article/272965

    相关文章

    Python进行JSON和Excel文件转换处理指南

    《Python进行JSON和Excel文件转换处理指南》在数据交换与系统集成中,JSON与Excel是两种极为常见的数据格式,本文将介绍如何使用Python实现将JSON转换为格式化的Excel文件,... 目录将 jsON 导入为格式化 Excel将 Excel 导出为结构化 JSON处理嵌套 JSON:

    Python使用openpyxl读取Excel的操作详解

    《Python使用openpyxl读取Excel的操作详解》本文介绍了使用Python的openpyxl库进行Excel文件的创建、读写、数据操作、工作簿与工作表管理,包括创建工作簿、加载工作簿、操作... 目录1 概述1.1 图示1.2 安装第三方库2 工作簿 workbook2.1 创建:Workboo

    SpringBoot集成EasyPoi实现Excel模板导出成PDF文件

    《SpringBoot集成EasyPoi实现Excel模板导出成PDF文件》在日常工作中,我们经常需要将数据导出成Excel表格或PDF文件,本文将介绍如何在SpringBoot项目中集成EasyPo... 目录前言摘要简介源代码解析应用场景案例优缺点分析类代码方法介绍测试用例小结前言在日常工作中,我们经

    一文解密Python进行监控进程的黑科技

    《一文解密Python进行监控进程的黑科技》在计算机系统管理和应用性能优化中,监控进程的CPU、内存和IO使用率是非常重要的任务,下面我们就来讲讲如何Python写一个简单使用的监控进程的工具吧... 目录准备工作监控CPU使用率监控内存使用率监控IO使用率小工具代码整合在计算机系统管理和应用性能优化中,监

    SpringBoot+EasyPOI轻松实现Excel和Word导出PDF

    《SpringBoot+EasyPOI轻松实现Excel和Word导出PDF》在企业级开发中,将Excel和Word文档导出为PDF是常见需求,本文将结合​​EasyPOI和​​Aspose系列工具实... 目录一、环境准备与依赖配置1.1 方案选型1.2 依赖配置(商业库方案)二、Excel 导出 PDF

    如何使用Lombok进行spring 注入

    《如何使用Lombok进行spring注入》本文介绍如何用Lombok简化Spring注入,推荐优先使用setter注入,通过注解自动生成getter/setter及构造器,减少冗余代码,提升开发效... Lombok为了开发环境简化代码,好处不用多说。spring 注入方式为2种,构造器注入和setter

    MySQL进行数据库审计的详细步骤和示例代码

    《MySQL进行数据库审计的详细步骤和示例代码》数据库审计通过触发器、内置功能及第三方工具记录和监控数据库活动,确保安全、完整与合规,Java代码实现自动化日志记录,整合分析系统提升监控效率,本文给大... 目录一、数据库审计的基本概念二、使用触发器进行数据库审计1. 创建审计表2. 创建触发器三、Java

    MySQL深分页进行性能优化的常见方法

    《MySQL深分页进行性能优化的常见方法》在Web应用中,分页查询是数据库操作中的常见需求,然而,在面对大型数据集时,深分页(deeppagination)却成为了性能优化的一个挑战,在本文中,我们将... 目录引言:深分页,真的只是“翻页慢”那么简单吗?一、背景介绍二、深分页的性能问题三、业务场景分析四、

    使用Python删除Excel中的行列和单元格示例详解

    《使用Python删除Excel中的行列和单元格示例详解》在处理Excel数据时,删除不需要的行、列或单元格是一项常见且必要的操作,本文将使用Python脚本实现对Excel表格的高效自动化处理,感兴... 目录开发环境准备使用 python 删除 Excphpel 表格中的行删除特定行删除空白行删除含指定

    SpringBoot结合Docker进行容器化处理指南

    《SpringBoot结合Docker进行容器化处理指南》在当今快速发展的软件工程领域,SpringBoot和Docker已经成为现代Java开发者的必备工具,本文将深入讲解如何将一个SpringBo... 目录前言一、为什么选择 Spring Bootjavascript + docker1. 快速部署与