VBA取消固定数目的列,就像Power QUery

如何解决VBA取消固定数目的列,就像Power QUery

在这里是相当新的,对于宏编码也很新。发现这个论坛对像我这样的初学者非常有帮助,所以我很高兴得到你们的帮助! ^^

我一直在搜寻我需要做的这段代码,可悲的是,尽管有些代码很接近,但是它实际上并没有满足我的需要,实际上这只是非常简单的情况。

例如,我有130列,其中13列必须是不可透视的。这么简单。 当然,行数可能会不时变化。

这与Power Query完美配合,但我很傻,vba不会执行Power Query。哈哈8o

我附上了一个示例文件,该文件可以显示如何显示我的数据,

其中A到E列是固定数组,F往后将是不可透视的主题。

希望有人真的可以在这方面为我提供帮助,因为我现在好像头发松了。大声笑。

非常感谢您!

让我知道我该如何回报你的好意。

编辑:所以我发现Powerquery也可以进行VBA,但是不幸的是,由于某种原因,我在这里遇到错误:

'Sub Macro10()

ActiveWorkbook.Queries.Add Name:="ProjectDetails (4)",Formula:= _
    "let" & Chr(13) & "" & Chr(10) & "    Source = Excel.CurrentWorkbook(){[Name=""ProjectDetails""]}[Content]," & Chr(13) & "" & Chr(10) & "    #""Changed Type"" = Table.TransformColumnTypes(Source,{{""Project"",Int64.Type},{""Project2"",{""Project Name"",type text},{""Strategic Business Unit"",{""Area"",{""Sub Area"",{""Business Line"",{""Department"",ty" & _
    "pe text},{""AECOM Project Review Category"",{""Customer Name"",{""Customer Type"",{""Project Manager"",{""Project Accountant"",{""Project Biller"",{""Regional Director"",{""Project Director"",{""Project Status"",{""End-Client Sector"",{" & _
    """Global Business Line"",{""AECOM Work"",{""AECOM Funding Source"",{""Distribution Rule"",{""Agreement"",{""CRM Tracking #"",{""Last Invoiced Date"",type any},{""Last EAC Date"",{""Scheduled Start Date"",type datetime},{""Scheduled Finish Date"",{""Forecast" & _
    " End Date"",{""AECOM Contract Type"",{""MTD Revenue"",type number},{""MTD Total Costs"",{""MTD DL"",{""MTD Fringe"",{""MTD Overhead"",{""MTD ODC"",{""MTD Subs"",{""NSR MTD"",{""MTD GM"",{""MTD GM % of Revenues"",typ" & _
    "e number},{""MTD NM"",{""Direct Labor Multiplier MTD"",{""Salary Cost Multiplier MTD"",{""MTD Bookings"",{""YTD Revenue"",{""YTD Total Costs"",{""YTD DL"",{""YTD Fringe"",{""YTD Overhead"",{""YTD ODC"",{""YTD Subs""," & _
    "type number},{""YTD NSR"",{""YTD GM"",{""YTD GM % of Revenue"",{""YTD NM"",{""YTD DLM"",{""YTD SCM"",{""YTD Bookings"",{""ITD Revenue"",{""ITD Total Costs"",{""ITD DL"",{""ITD Fringe"",{""ITD Overhead""" & _
    ",{""ITD ODC"",{""ITD Subs"",{""ITD NSR"",{""ITD GM"",{""ITD GM% of Revenue"",{""ITD NM"",{""ITD DLM"",{""ITD SCM"",{""Funded Value"",{""Backlog"",{""Unbilled >30"",{""Unbilled (BIEE)"",ty" & _
    "pe number},{""ITD Billed"",{""Billing > 60"",{""Trade AR"",{""Retention"",{""Appr Revenue Budget"",{""Appr ODC Budget"",{""Appr Subs Budget"",{""Appr Contingency Budget"",{""Appr DL Budget"",{""Appr Fringe Budget"",{""" & _
    "Appr Cost Budget"",{""Appr DLM Budget"",{""Appr SCM Budget"",{""Frcst Revenue Budget"",{""Frcst ODC Budget"",{""Frcst Subs Budget"",{""Frcst Contingency Budget"",{""Frcst DL Budget"",{""Frcst Fringe Budget"",{""Frcst Overhead Budget" & _
    """,{""Frcst Cost Budget"",{""Frcst DLM"",{""Frcst SCM"",{""Source System Description"",{""Source System ID"",{""Valid for Review?"",{""Project Accountant Required"",{""Invoiced Over Contract "",{""Est. Collections over Contact "",type numb" & _
    "er},{""Current ETC "",{""Trended Costs"",{""Est. ETC at Month End"",{""MTD NM% of NSR"",{""YTD NM% of NSR"",{""ITD NM% of NSR"",{""Percent Complete"",{""Backlog Burn Rate"",{""Billing Backlog"",{""Unbilled Reserve"",{""AR Reserve"",{""YTD Lost Margin"",{""Project Manager Location"",{""ROCV"",{""Low to Zero Backlog"",{""Negative Margin MTD"",{""Negative Margin YTD"",{""Negative Margin ITD"",type text}})," & Chr(13) & "" & Chr(10) & "    #""Unpivoted Columns"" = Table.UnpivotOtherColumns(#""Changed Type"",{""Project"",""Project" & _
    "2"",""Project Name"",""Strategic Business Unit"",""Area"",""Sub Area"",""Business Line"",""Department"",""AECOM Project Review Category"",""Customer Name"",""Customer Type"",""Project Manager"",""Project Accountant"",""Project Biller"",""Regional Director"",""Project Director"",""Project Status"",""End-Client Sector"",""Global Business Line"",""AEC" & _
    "OM Work"",""AECOM Funding Source"",""Distribution Rule"",""Agreement"",""CRM Tracking #"",""Last Invoiced Date"",""Last EAC Date"",""Scheduled Start Date"",""Scheduled Finish Date"",""Forecast End Date"",""AECOM Contract Type"",""MTD Revenue"",""MTD Total Costs"",""MTD DL"",""MTD Fringe"",""MTD Overhead"",""MTD ODC"",""MTD Subs"",""NSR MTD"",""MTD" & _
    " GM"",""MTD GM % of Revenues"",""MTD NM"",""Direct Labor Multiplier MTD"",""Salary Cost Multiplier MTD"",""MTD Bookings"",""YTD Revenue"",""YTD Total Costs"",""YTD DL"",""YTD Fringe"",""YTD Overhead"",""YTD ODC"",""YTD Subs"",""YTD NSR"",""YTD GM"",""YTD GM % of Revenue"",""YTD NM"",""YTD DLM"",""YTD SCM"",""YTD Bookings"",""ITD Revenue"",""ITD " & _
    "Total Costs"",""ITD DL"",""ITD Fringe"",""ITD Overhead"",""ITD ODC"",""ITD Subs"",""ITD NSR"",""ITD GM"",""ITD GM% of Revenue"",""ITD NM"",""ITD DLM"",""ITD SCM"",""Funded Value"",""Backlog"",""Unbilled >30"",""Unbilled (BIEE)"",""ITD Billed"",""Billing > 60"",""Trade AR"",""Retention"",""Appr Revenue Budget"",""Appr ODC Budget"",""Appr Subs Bu" & _
    "dget"",""Appr Contingency Budget"",""Appr DL Budget"",""Appr Fringe Budget"",""Appr Cost Budget"",""Appr DLM Budget"",""Appr SCM Budget"",""Frcst Revenue Budget"",""Frcst ODC Budget"",""Frcst Subs Budget"",""Frcst Contingency Budget"",""Frcst DL Budget"",""Frcst Fringe Budget"",""Frcst Overhead Budget"",""Frcst Cost Budget"",""Frcst DLM"",""Frcst SCM" & _
    """,""Source System Description"",""Source System ID"",""Valid for Review?"",""Project Accountant Required"",""Invoiced Over Contract "",""Est. Collections over Contact "",""Current ETC "",""Trended Costs"",""Est. ETC at Month End"",""MTD NM% of NSR"",""YTD NM% of NSR"",""ITD NM% of NSR"",""Percent Complete"",""Backlog Burn Rate"",""Billing Backlog""," & _
    """Unbilled Reserve"",""AR Reserve"",""YTD Lost Margin"",""Project Manager Location""},""Attribute"",""Value"")" & Chr(13) & "" & Chr(10) & "in" & Chr(13) & "" & Chr(10) & "    #""Unpivoted Columns"""
ActiveWorkbook.Worksheets.Add
With ActiveSheet.ListObjects.Add(SourceType:=0,Source:= _
    "OLEDB;Provider=Microsoft.Mashup.OleDb.1;Data Source=$Workbook$;Location=""ProjectDetails (4)"";Extended Properties=""""" _,Destination:=Range("$A$1")).QueryTable
    .CommandType = xlCmdSql
    .CommandText = Array("SELECT * FROM [ProjectDetails (4)]")
    .RowNumbers = False
    .FillAdjacentFormulas = False
    .PreserveFormatting = True
    .RefreshOnFileOpen = False
    .BackgroundQuery = True
    .RefreshStyle = xlInsertDeleteCells
    .SavePassword = False
    .SaveData = True
    .AdjustColumnWidth = True
    .RefreshPeriod = 0
    .PreserveColumnInfo = True
    .ListObject.DisplayName = "ProjectDetails__4"
    .Refresh BackgroundQuery:=False
End With
Application.CommandBars("Queries and Connections").Visible = False

结束字幕 '

[![在此处输入图片描述] [1]] [1] [1]:https://i.stack.imgur.com/SQsdQ.png

解决方法

我发布的链接中的$ pip3 install matplotlib Collecting matplotlib Using cached matplotlib-3.3.2.tar.gz (37.9 MB) Requirement already satisfied: certifi>=2020.06.20 in ./files/usr/lib/python3.9/site-packages (from matplotlib) (2020.6.20) Requirement already satisfied: cycler>=0.10 in ./files/usr/lib/python3.9/site-packages (from matplotlib) (0.10.0) Requirement already satisfied: kiwisolver>=1.0.1 in ./files/usr/lib/python3.9/site-packages (from matplotlib) (1.2.0) Requirement already satisfied: numpy>=1.15 in ./files/usr/lib/python3.9/site-packages (from matplotlib) (1.19.3) Requirement already satisfied: pillow>=6.2.0 in ./files/usr/lib/python3.9/site-packages (from matplotlib) (8.0.1) Requirement already satisfied: pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=2.0.3 in ./files/usr/lib/python3.9/site-packages (from matplotlib) (2.4.7) Requirement already satisfied: python-dateutil>=2.1 in ./files/usr/lib/python3.9/site-packages (from matplotlib) (2.8.1) Requirement already satisfied: six in ./files/usr/lib/python3.9/site-packages (from cycler>=0.10->matplotlib) (1.15.0) Building wheels for collected packages: matplotlib Building wheel for matplotlib (setup.py) ... error ERROR: Command errored out with exit status 1: command: /data/data/com.termux/files/usr/bin/python3 -u -c 'import sys,setuptools,tokenize; sys.argv[0] = '"'"'/data/data/com.termux/files/usr/tmp/pip-install-zejjxir0/matplotlib/setup.py'"'"'; __file__='"'"'/data/data/com.termux/files/usr/tmp/pip-install-zejjxir0/matplotlib/setup.py'"'"';f=getattr(tokenize,'"'"'open'"'"',open)(__file__);code=f.read().replace('"'"'\r\n'"'"','"'"'\n'"'"');f.close();exec(compile(code,__file__,'"'"'exec'"'"'))' bdist_wheel -d /data/data/com.termux/files/usr/tmp/pip-wheel-6cp2oysk cwd: /data/data/com.termux/files/usr/tmp/pip-install-zejjxir0/matplotlib/ Complete output (580 lines): Edit setup.cfg to change the build options; suppress output with --quiet. BUILDING MATPLOTLIB matplotlib: yes [3.3.2] python: yes [3.9.0 (default,Oct 8 2020,15:54:02) [Clang 9.0.8 (https://android.googlesource.com/toolchain/llvm-project 98c855489] platform: yes [linux] sample_data: yes [installing] tests: no [skipping due to configuration] macosx: no [Mac OS-X only] running bdist_wheel running build running build_py creating build creating build/lib.linux-aarch64-3.9 copying lib/pylab.py -> build/lib.linux-aarch64-3.9 creating build/lib.linux-aarch64-3.9/matplotlib copying lib/matplotlib/__init__.py -> build/lib.linux-aarch64-3.9/matplotlib copying lib/matplotlib/_animation_data.py -> build/lib.linux-aarch64-3.9/matplotlib copying lib/matplotlib/_cm.py -> build/lib.linux-aarch64-3.9/matpl ... ... copying lib/matplotlib/mpl-data/sample_data/membrane.dat -> build/lib.linux-aarch64-3.9/matplotlib/mpl-data/sample_data UPDATING build/lib.linux-aarch64-3.9/matplotlib/_version.py set build/lib.linux-aarch64-3.9/matplotlib/_version.py to '3.3.2' running build_ext creating data creating data/data creating data/data/com.termux creating data/data/com.termux/files creating data/data/com.termux/files/usr creating data/data/com.termux/files/usr/tmp aarch64-linux-android-clang -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -fstack-protector-strong -O3 -fstack-protector-strong -O3 -Wno-deprecated-declarations -Wno-unreachable-code -fPIC -I/data/data/com.termux/files/usr/include/python3.9 -c /data/data/com.termux/files/usr/tmp/tmpf47ko78k.cpp -o data/data/com.termux/files/usr/tmp/tmpf47ko78k.o -fvisibility=hidden aarch64-linux-android-clang -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -fstack-protector-strong -O3 -fstack-protector-strong -O3 -Wno-deprecated-declarations -Wno-unreachable-code -fPIC -I/data/data/com.termux/files/usr/include/python3.9 -c /data/data/com.termux/files/usr/tmp/tmp4auaqklr.cpp -o data/data/com.termux/files/usr/tmp/tmp4auaqklr.o -fvisibility-inlines-hidden Extracting freetype-2.6.1.tar.gz Building freetype in build/freetype-2.6.1 error: [Errno 13] Permission denied: './configure' ---------------------------------------- ERROR: Failed building wheel for matplotlib Running setup.py clean for matplotlib Failed to build matplotlib Installing collected packages: matplotlib Running setup.py install for matplotlib ... error ERROR: Command errored out with exit status 1: command: /data/data/com.termux/files/usr/bin/python3 -u -c 'import sys,tokenize; sys.argv[0] = '"'"'/data/data/com.termux/files/usr/tmp/pip-install-3w4igc1k/matplotlib/setup.py'"'"'; __file__='"'"'/data/data/com.termux/files/usr/tmp/pip-install-3w4igc1k/matplotlib/setup.py'"'"';f=getattr(tokenize,'"'"'exec'"'"'))' install --record /data/data/com.termux/files/usr/tmp/pip-record-jffs1p2w/install-record.txt --single-version-externally-managed --compile --install-headers /data/data/com.termux/files/usr/include/python3.9/matplotlib cwd: /data/data/com.termux/files/usr/tmp/pip-install-3w4igc1k/matplotlib/ Complete output (572 lines): Edit setup.cfg to change the build options; suppress output with --quiet. BUILDING MATPLOTLIB matplotlib: yes [3.3.2] python: yes [3.9.0 (default,15:54:02) [Clang 9.0.8 (https://android.googlesource.com/toolchain/llvm-project 98c855489] platform: yes [linux] sample_data: yes [installing] tests: no [skipping due to configuration] macosx: no [Mac OS-X only] running install running build running build_py creating build/lib.linux-aarch64-3.9 copying lib/pylab.py -> build/lib.linux-aarch64-3.9 creating build/lib.linux-aarch64-3.9/matplotlib copying lib/matplotlib/__init__.py -> build/lib.linux-aarch64-3.9/matplotlib copying lib/matplotlib/_animation_data.py -> build/lib.linux-aarch64-3.9/matplotlib copying lib/matplotlib/_cm.py -> build/lib.linux-aarch64-3.9/matplotlib ... ... copying lib/matplotlib/mpl-data/images/zoom_to_rect.png -> build/lib.linux-aarch64-3.9/matplotlib/mpl-data/images copying lib/matplotlib/mpl-data/sample_data/README.txt -> build/lib.linux-aarch64-3.9/matplotlib/mpl-data/sample_data UPDATING build/lib.linux-aarch64-3.9/matplotlib/_version.py set build/lib.linux-aarch64-3.9/matplotlib/_version.py to '3.3.2' running build_ext aarch64-linux-android-clang -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -fstack-protector-strong -O3 -fstack-protector-strong -O3 -Wno-deprecated-declarations -Wno-unreachable-code -fPIC -I/data/data/com.termux/files/usr/include/python3.9 -c /data/data/com.termux/files/usr/tmp/tmp8gd5nxqf.cpp -o data/data/com.termux/files/usr/tmp/tmp8gd5nxqf.o -fvisibility=hidden aarch64-linux-android-clang -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -fstack-protector-strong -O3 -fstack-protector-strong -O3 -Wno-deprecated-declarations -Wno-unreachable-code -fPIC -I/data/data/com.termux/files/usr/include/python3.9 -c /data/data/com.termux/files/usr/tmp/tmpfcioek2o.cpp -o data/data/com.termux/files/usr/tmp/tmpfcioek2o.o -fvisibility-inlines-hidden Building freetype in build/freetype-2.6.1 error: [Errno 13] Permission denied: './configure' ---------------------------------------- ERROR: Command errored out with exit status 1: /data/data/com.termux/files/usr/bin/python3 -u -c 'import sys,'"'"'exec'"'"'))' install --record /data/data/com.termux/files/usr/tmp/pip-record-jffs1p2w/install-record.txt --single-version-externally-managed --compile --install-headers /data/data/com.termux/files/usr/include/python3.9/matplotlib Check the logs for full command output. 函数没有任何更改,这应该根据您发布的文件执行您想要的操作:

UnPivotData

编辑-添加Sub Tester() Dim p 'get the unpivoted data as a 2-D array p = UnPivotData(ThisWorkbook.Sheets("data source").Range("A2").CurrentRegion,_ 118,True,True) 'I added a new sheet for the output With Sheets("output2") .Cells.ClearContents .Range("A1").Resize(UBound(p,1),UBound(p,2)).Value = p 'populate array to sheet End With 'EDIT: alternative (slower) method to populate the sheet ' from the pivoted dataset. Might need to use this ' if you have a large amount of data ' Dim r As Long,c As Long ' For r = 1 To UBound(p,1) ' For c = 1 To UBound(p,2) ' Sheets("Sheet2").Cells(r,c).Value = p(r,c) ' Next c ' Next r End Sub 函数:

UnPivotData

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


依赖报错 idea导入项目后依赖报错,解决方案:https://blog.csdn.net/weixin_42420249/article/details/81191861 依赖版本报错:更换其他版本 无法下载依赖可参考:https://blog.csdn.net/weixin_42628809/a
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下 2021-12-03 13:33:33.927 ERROR 7228 [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPL
错误1:gradle项目控制台输出为乱码 # 解决方案:https://blog.csdn.net/weixin_43501566/article/details/112482302 # 在gradle-wrapper.properties 添加以下内容 org.gradle.jvmargs=-Df
错误还原:在查询的过程中,传入的workType为0时,该条件不起作用 <select id="xxx"> SELECT di.id, di.name, di.work_type, di.updated... <where> <if test=&qu
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct redisServer’没有名为‘server_cpulist’的成员 redisSetCpuAffinity(server.server_cpulist); ^ server.c: 在函数‘hasActiveC
解决方案1 1、改项目中.idea/workspace.xml配置文件,增加dynamic.classpath参数 2、搜索PropertiesComponent,添加如下 <property name="dynamic.classpath" value="tru
删除根组件app.vue中的默认代码后报错:Module Error (from ./node_modules/eslint-loader/index.js): 解决方案:关闭ESlint代码检测,在项目根目录创建vue.config.js,在文件中添加 module.exports = { lin
查看spark默认的python版本 [root@master day27]# pyspark /home/software/spark-2.3.4-bin-hadoop2.7/conf/spark-env.sh: line 2: /usr/local/hadoop/bin/hadoop: No s
使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams['font.sans-serif'] = ['SimHei'] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -> systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping("/hires") public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate<String
使用vite构建项目报错 C:\Users\ychen\work>npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-