简体   繁体   English

Excel宏或函数:如果单元格不为空,则使用循环值(来自另一张纸)填充单元格区域(A列)

[英]Excel Macro or Function: Populate a cell range (Column A) with a looped values (from another sheet) if cell is not blank

Need help for someone trying to learn macro coding. 需要帮助尝试学习宏编码的人。

Sheet 1 has two Columns A & B. Sheet 2, Col A has a range of value. 工作表1有两个A和B栏。工作表2的A列有一个值范围。 I wanted to fill Sheet 1 Column B with a value on Sheet 2 Column A if Sheet 1 Column A cell is not empty. 如果工作表1列A单元格不为空,我想用工作表2列A上的值填充工作表1列B。

Illustration below. 下图。

Sheet2 Col A
Brian, 
David,
Nicole,
Aspen,

Col A                  
Apple         
Banana        
Orange        
Lemon         
Mango         
Strawberry    
Grape      

Col B should get filled by looping with the names, Brian for Apple and then David for Banana, and so on and then go back to David and so on until Grape for Nicole.. 上校B的名称应该是循环的,Brian是Apple的名字,然后是David的Banana名字,依此类推,然后回到David,依此类推,直到Grape的名字是Nicole。

Please help provide with a function or macro vba code to accomplish this. 请帮助提供函数或宏vba代码以完成此操作。

One way is to use INDIRECT : 一种方法是使用INDIRECT

=INDIRECT("Sheet2!A" & MOD(ROW()+3,4)+1)

This assumes the names are in A1:A4 假设名称在A1:A4

Edit: and I just thought of a way to use INDEX instead: 编辑:我只是想了一种使用INDEX的方法:

=INDEX(Sheet2!A$1:A$4,MOD(ROW()+3,4)+1)

MOD will return the remainder of the row number divided by n (in this case, 4 ). MOD将返回行号的其余部分除以n (在这种情况下为4 )。 This will result in a number between 0 and 3 ( n-1 ), inclusively. 这将导致数字介于03n-1 )之间(含03 )。 the sequence for rows 1-6 is 1, 2, 3, 0, 1, 2 . 对于行序列1-61, 2, 3, 0, 1, 2

By adding 3 ( n-1 ) to the row number, I can get the sequence for rows 1-6 to become 0, 1, 2, 3, 0, 1 通过将3n-1 )添加到行号,我可以获得1-6行的序列变为0, 1, 2, 3, 0, 1

Then adding 1 to the mod makes the sequence: 1, 2, 3, 4, 1, 2 , which I can then use as the index for the table of names 然后在mod上加1即可形成序列: 1, 2, 3, 4, 1, 2然后我可以将其用作名称表的索引

For 12 names you will want to use: 对于12个名称,您将要使用:

=INDEX(F$1:F$12,MOD(ROW()+11,12)+1)

暂无
暂无

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

相关问题 Macro Excel可根据单元格匹配将范围单元格从一张纸复制到另一张纸,如果不匹配,则跳过单元格 - Macro Excel to copy range cells from one sheet to another based on cell match and skip cell if no match Excel宏复制单元格范围并将数据粘贴到另一个工作表 - Excel Macro Copy cell range & paste data one sheet to another 我们可以使用单元格范围验证从 EPPLUS 的另一张表中填充 excel 中的下拉列表吗 - Can we use Cell Range Validation to populate a dropdown list in excel from another sheet in EPPLUS Excel宏可将数据从一个表移动到另一列,并基于列名和单元格内容 - Excel macro to move data from one sheet to another based column name and cell content 根据列中的值填充其他工作表中的excel单元格值 - Populate excel cell value from a different sheet based on value in a column 用于保存 Excel 工作表的宏,其中包含来自单元格值的文件名和路径 - Macro to save Excel sheet with file name and path from cell values Excel宏和VBA,将单元格范围复制到另一个工作表(转置并基于另一个值) - Excel Macro & VBA, Copy Cell Range to another sheet (transposed and based on another value) 在Excel中,如何根据一个工作表中的行与另一工作表中的列之间的匹配来填充单元格 - In Excel, how to populate cell based on match between row in one sheet and column in another sheet Excel 宏在工作表中查找单元格并将整行复制到另一个工作表中 - Excel macro to find a cell in a sheet and copy the entire row in another sheet 如何使用Excel从一个工作表中的一个单元格填充另一个工作表中的一个单元格 - How to populate a cell in one sheet from a cell in the other using excel
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM