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调用Orator ORM进行数据库操作

    《Python调用OratorORM进行数据库操作》OratorORM是一个功能丰富且灵活的PythonORM库,旨在简化数据库操作,它支持多种数据库并提供了简洁且直观的API,下面我们就... 目录Orator ORM 主要特点安装使用示例总结Orator ORM 是一个功能丰富且灵活的 python O

    Nginx设置连接超时并进行测试的方法步骤

    《Nginx设置连接超时并进行测试的方法步骤》在高并发场景下,如果客户端与服务器的连接长时间未响应,会占用大量的系统资源,影响其他正常请求的处理效率,为了解决这个问题,可以通过设置Nginx的连接... 目录设置连接超时目的操作步骤测试连接超时测试方法:总结:设置连接超时目的设置客户端与服务器之间的连接

    使用 sql-research-assistant进行 SQL 数据库研究的实战指南(代码实现演示)

    《使用sql-research-assistant进行SQL数据库研究的实战指南(代码实现演示)》本文介绍了sql-research-assistant工具,该工具基于LangChain框架,集... 目录技术背景介绍核心原理解析代码实现演示安装和配置项目集成LangSmith 配置(可选)启动服务应用场景

    如何通过海康威视设备网络SDK进行Java二次开发摄像头车牌识别详解

    《如何通过海康威视设备网络SDK进行Java二次开发摄像头车牌识别详解》:本文主要介绍如何通过海康威视设备网络SDK进行Java二次开发摄像头车牌识别的相关资料,描述了如何使用海康威视设备网络SD... 目录前言开发流程问题和解决方案dll库加载不到的问题老旧版本sdk不兼容的问题关键实现流程总结前言作为

    SpringBoot中使用 ThreadLocal 进行多线程上下文管理及注意事项小结

    《SpringBoot中使用ThreadLocal进行多线程上下文管理及注意事项小结》本文详细介绍了ThreadLocal的原理、使用场景和示例代码,并在SpringBoot中使用ThreadLo... 目录前言技术积累1.什么是 ThreadLocal2. ThreadLocal 的原理2.1 线程隔离2

    Python创建Excel的4种方式小结

    《Python创建Excel的4种方式小结》这篇文章主要为大家详细介绍了Python中创建Excel的4种常见方式,文中的示例代码简洁易懂,具有一定的参考价值,感兴趣的小伙伴可以学习一下... 目录库的安装代码1——pandas代码2——openpyxl代码3——xlsxwriterwww.cppcns.c

    Spring排序机制之接口与注解的使用方法

    《Spring排序机制之接口与注解的使用方法》本文介绍了Spring中多种排序机制,包括Ordered接口、PriorityOrdered接口、@Order注解和@Priority注解,提供了详细示例... 目录一、Spring 排序的需求场景二、Spring 中的排序机制1、Ordered 接口2、Pri

    Python利用PIL进行图片压缩

    《Python利用PIL进行图片压缩》有时在发送一些文件如PPT、Word时,由于文件中的图片太大,导致文件也太大,无法发送,所以本文为大家介绍了Python中图片压缩的方法,需要的可以参考下... 有时在发送一些文件如PPT、Word时,由于文件中的图片太大,导致文件也太大,无法发送,所有可以对文件中的图

    如何使用Spring boot的@Transactional进行事务管理

    《如何使用Springboot的@Transactional进行事务管理》这篇文章介绍了SpringBoot中使用@Transactional注解进行声明式事务管理的详细信息,包括基本用法、核心配置... 目录一、前置条件二、基本用法1. 在方法上添加注解2. 在类上添加注解三、核心配置参数1. 传播行为(

    Python给Excel写入数据的四种方法小结

    《Python给Excel写入数据的四种方法小结》本文主要介绍了Python给Excel写入数据的四种方法小结,包含openpyxl库、xlsxwriter库、pandas库和win32com库,具有... 目录1. 使用 openpyxl 库2. 使用 xlsxwriter 库3. 使用 pandas 库