简体   繁体   English

在表单上列出Microsoft Excel数据

[英]Listing Microsoft Excel data on a form

I have a well laid out excel spreadsheet that looks something like this: 我有一个布局合理的excel电子表格,看起来像这样:

| NAME | SERIAL | GUN1 | OPTIC1 | OPTIC 2 |
+-----------------------------------------+
| Jonn | W0465  | MK19 | 006000 |         | 
+-----------------------------------------+
| Jimm | W1465  | MD24 |        | 455212  | 
+-----------------------------------------+

And I'm wanting it to be able to generate that data into another sheet that contains a form. 我希望它能够将数据生成到另一个包含表单的工作表中。 On this form, there is 1 row per item (gun1, optic, etc.) but not everyone has the exact same equipment (Jonn has OPTIC1 while Jimm has OPTIC2, however some people may not have an optic at all). 在此表格上,每件物品(枪1,光学器件等)有1行,但并不是每个人都具有完全相同的设备(琼恩拥有OPTIC1,而吉姆拥有OPTIC2,但是有些人可能根本没有光学器件)。

The form will look like this (using the sample data above). 表单将如下所示(使用上面的示例数据)。

|  TYPE  | SERIAL | NAME |
+------------------------+
|  GUN1  |  MK19  | Jonn |
+------------------------+
| OPTIC1 | 006000 | Jonn |
+------------------------+
|  GUN1  |  MD24  | Jimm |
+------------------------+
| OPTIC2 | 455212 | Jimm |
+------------------------+

Any idea on how I can efficiently do this? 关于如何有效执行此操作的任何想法? There needs to be conditional statements and references, but I'm not sure how to effectively do all this. 需要有条件的语句和引用,但是我不确定如何有效地完成所有这些操作。

I was able to successfully reference the data using =SHEET1!$C2 etc. And I then made 2 rows for "Jonn" and everything was filled in perfectly (using absolute and relative references). 我能够使用=SHEET1!$C2等成功地引用数据。然后我为“ Jonn”制作了2行,并且所有内容都完美填充(使用绝对引用和相对引用)。 However, when I selected those two rows and tried to duplicate them, it then generated rows =SHEET1!$C4 rather than =SHEET1!$C3 (note the C4 and C3). 但是,当我选择这两行并尝试复制它们时,它将生成=SHEET1!$C4而不是=SHEET1!$C3 (请注意C4和C3)。 Since Jonn's data was two rows long on the form, the relative references would skip the 3rd row in the original excel sheet. 由于Jonn的数据在表单上有两行长,因此相对引用将跳过原始excel工作表中的第三行。 Make sense? 说得通? Please ask questions 请问问题

Thanks 谢谢

So were ignoring the SERIAL column in table 1 (this is what confused me a little). 因此忽略了表1中的SERIAL列(这让我有些困惑)。

If you can guarantee that you will have either OPTIC1 or OPTIC2 (not both) then using worksheet functions would be possible. 如果可以保证将拥有OPTIC1或OPTIC2(不是全部),则可以使用工作表功能。

If there is a possiblity that you could have BOTH then you still can do it, but you might end up with gaps in your list. 如果有可能两者兼有,那么您仍然可以做到,但最终可能会出现空白。

I've assumed that you can have ONE optic, not both and that row 1 on both of your sheets are used as column titles. 我假设您可以使用一个光学元件,但不能同时使用两个光学元件,并且您将两张纸上的第1行用作列标题。

You can use the ROW() function and some maths to generate your list. 您可以使用ROW()函数和一些数学运算来生成列表。

Sheet2!A2 = =IF((ABS(ROW()/2)+1-(INT(ROW()/2)+1))=0,"GUN1",IF(INDIRECT("Sheet1!D" & (INT(ROW()/2)+1))="","OPTIC2","OPTIC1")) Sheet2!A2 = =IF((ABS(ROW()/2)+1-(INT(ROW()/2)+1))=0,"GUN1",IF(INDIRECT("Sheet1!D" & (INT(ROW()/2)+1))="","OPTIC2","OPTIC1"))

Sheet2!B2 = =IF((ABS(ROW()/2)+1-(INT(ROW()/2)+1))=0,INDIRECT("Sheet1!C" & (INT(ROW()/2)+1)),IF(INDIRECT("Sheet1!D" & (INT(ROW()/2)+1))="",INDIRECT("Sheet1!E" & (INT(ROW()/2)+1)),INDIRECT("Sheet1!D" & (INT(ROW()/2)+1)))) Sheet2!B2 = =IF((ABS(ROW()/2)+1-(INT(ROW()/2)+1))=0,INDIRECT("Sheet1!C" & (INT(ROW()/2)+1)),IF(INDIRECT("Sheet1!D" & (INT(ROW()/2)+1))="",INDIRECT("Sheet1!E" & (INT(ROW()/2)+1)),INDIRECT("Sheet1!D" & (INT(ROW()/2)+1))))

Sheet2!C2 = =INDIRECT("Sheet1!A" & INT(ROW()/2)+1) Sheet2!C2 = =INDIRECT("Sheet1!A" & INT(ROW()/2)+1)

These formulas should then be auto-filled down the sheet as far as required (there is no checking to see if the rows it is looking at are populated) 然后,应根据需要将这些公式自动填入工作表(不检查是否查看了正在查看的行)

You might want to look into a VBA Solution as it would be much easier to maintain should you need to add extra columns or if you could have both optics. 您可能需要研究VBA解决方案,因为如果您需要添加额外的列或者如果您同时拥有两个光学元件,则维护起来会容易得多。

UPDATE 更新

Re-read your question and see that having NO optic is an option, which my code wont understand and leave you with some half populated rows. 重新阅读您的问题,看看没有光学元件是一种选择,我的代码无法理解,并给您留下了一半的填充行。

You'll need to use VBA. 您需要使用VBA。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM