[英]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:
你可以以此为灵感来获得你所需要的:
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.