简体   繁体   English

Excel - 将 A 列中的数据导出到基于 B 列的文本文件中

[英]Excel - Export Data from Column A into a text file based on Column B

Apologies in advance for my inability.为我的无能提前道歉。 I honestly have no idea how to handle this, I've only just started doing VBA. and only for specific tasks, So far Google and StackOverflow has provided what I was looking for.老实说,我不知道如何处理这个问题,我才刚刚开始做 VBA。而且只针对特定任务,到目前为止,Google 和 StackOverflow 已经提供了我正在寻找的东西。 but I cannot find anything that explains what I am trying to do.但我找不到任何可以解释我正在尝试做的事情的东西。

Any advice would be greatly appreciated!任何建议将不胜感激!

I am looking to populate a number of SQL scripts using data from Excel.我希望使用 Excel 中的数据填充多个 SQL 脚本。

In one column there is a list of usernames.在一列中有一个用户名列表。 In an adjacent column, there is a list of locations.在相邻的列中,有一个位置列表。

I have a template of a SQL script, and I need a TXT file generated for each location, with the relevant users inserted.我有一个 SQL 脚本模板,我需要为每个位置生成一个 TXT 文件,并插入相关用户。

For example, if this were the data set: Table Example例如,如果这是数据集:表示

And this is the script template:这是脚本模板:

LOCATIONA位置A

update USERTABLE set ACCOUNT_LOCKED = '1' where USERID in (%LOCATIONA_USERS%);更新 USERTABLE 设置 ACCOUNT_LOCKED = '1' 其中 USERID 在 (%LOCATIONA_USERS%) 中;

LOCATIONB地点B

update USERTABLE set ACCOUNT_LOCKED = '1' where USERID in (%LOCATIONB_USERS%);更新 USERTABLE 设置 ACCOUNT_LOCKED = '1' 其中 USERID 在 (%LOCATIONB_USERS%) 中;

The output would need to be like this: output 需要像这样:

LOCATIONA位置A

update USERTABLE set ACCOUNT_LOCKED = '1' where USERID in ('User1','User2','User3','User4','User5');更新 USERTABLE 设置 ACCOUNT_LOCKED = '1' where USERID in ('User1','User2','User3','User4','User5');

LOCATIONB地点B

update USERTABLE set ACCOUNT_LOCKED = '1' where USERID in ('User6','User7','User8','User9','User10','User11','User12');更新USERTABLE set ACCOUNT_LOCKED = '1' where USERID in ('User6','User7','User8','User9','User10','User11','User12');

It could either export to a single file, but with a separate script for each location, or a separate file per location.它可以导出到单个文件,但每个位置都有一个单独的脚本,或者每个位置一个单独的文件。

I imagine for someone who knows, this is probably really simple!我想对于知道的人来说,这可能真的很简单! However I am not that person!然而我不是那个人!

Thanks in advance!提前致谢!

I have created a similar dataset, with some formulas.我创建了一个类似的数据集,其中包含一些公式。 You can inspire yourself on this in order to get what you need:你可以以此为灵感来获得你所需要的:

  • Column A contains the names of the locations. A 列包含位置的名称。
  • Column B contains the names of the users. B 列包含用户的姓名。
  • Column C filters on "LocationA", the formula is shown in C1. C列对“LocationA”进行过滤,公式见C1。
  • Column D filters on "LocationB", the formula (shown in D1) is similar to the one in C1. D列过滤“LocationB”,公式(D1所示)与C1类似。
  • A TextJoin based formula is used for collecting the list of users, both for "LocationA" and "LocationB", the formula ( =TEXTJOIN(",",TRUE,C2:C6) ) is shown preceeding the values:基于TextJoin的公式用于收集“LocationA”和“LocationB”的用户列表,公式 ( =TEXTJOIN(",",TRUE,C2:C6) ) 显示在值之前:

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从字典中导出具有特定列名的excel文件中的数据? - How to export data in an excel file with specific column names from a dictionary? 使用SmartXLS将数据从Excel文件(带有日期列)导出到DataGrid - Export data from excel file (with a date column) to DataGrid using SmartXLS 根据Microsoft Excel中A列中的值从B列中删除重复项 - Remove duplicates from column B based on values in column A in Microsoft Excel 如何将基于列名的完整行数据导出到新的 Excel 文件? - How to export complete row data based on column name to new Excel file? Excel 2003:将A列中的值与B列匹配,然后从B列中提取数据 - Excel 2003: Match value in column A with column B, then pull data from column B 将数据从Excel导出到文本文件 - Export Data from Excel to Text File 将 Excel 工作簿中特定列的数据添加到文本文件 - Adding data from a specific column in Excel Workbook to a text file 将A列中的文本与B列中的文本合并,输出到C列-Excel - merge text in column A with text in column B, output into column C - excel 在多张工作表的C列中将基于文本的数据列出到excel主表中的一列中 - listing text-based data from column C in multiple sheets into a single column in a master sheet in excel 更改列标题文本-将查询数据导出到Excel - change column header text - Export query Data to Excel
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM