-1

下面的数据出现在工作表 1 中。我需要将工作表 2 中的数据分成两列,第一列是“月-年”格式,第二列输出下面对应月/年的数据。

例如:

Year    Jan Feb Mar Apr May Jun Jul Aug Sep

1913    9.8 9.8 9.8 9.8 9.7 9.8 9.9 9.9 10.0    

1914   10.0 9.9 9.9 9.8 9.9 9.9 10  10  10

输出必须采用以下格式:

MM-YYYY / Data  
Jan-1913 /    9.8  
Feb-1913 / 9.8  

我需要使用 Excel 公式而不是 VBA 来执行此操作。

4

2 回答 2

0

I hope you know how to write macros. (Google visualbasic+excel)

Basically you want to loop over your variables, and concatenate (fancy computer term for combining) your cells. I believe this should work.

Dim monthIdx as Integer
Dim yearIdx as Integer

Dim writeColumnIdx as Integer
Dim myConcatenatedDate as String
writeRowIdx = 2
for yearIdx is 2 to 94
  for monthIdx is 2 to 10
    myConcatenatedDate = Cells(yearIdx, 1).value + "-" + Cells(1, monthIdx).value
    Cells(writeRowIdx, monthIdx).value = myConcatenatedDate
  next monthIdx
next yearIdx

Note that the easier solution would be to type Jan-1900 in one cell, move one over and type Feb-1900... then highlight both the cells, click your cursor over the top-left corner of both boxes and then drag it over adinfinem (maybe). Excel is pretty good at doing those types of things (unless if you only want jan-sep).

于 2013-09-20T19:51:21.933 回答
0

使用连接?

=CONCATENATE(B$1,"-",$A2)

并向下拖动公式。

这假设月份在第一行,年份在第一列,B1 中为 Jan,A2 中为 1913。

或使用:

=B$1&"-"&$A2

美元符号锁定了行或列,这样您就不必每次都重新调整公式。

编辑:好像你只想填写一列......

Jan-1913在单元格 B2 中键入,然后键入Feb-1913。选择两个单元格并向下拖动。

在此处输入图像描述

如果日期不显示为mm-yyyy,只需应用自定义格式。

并填写、复制并粘贴为 B 列内容的值。编辑:有关附加部分的附录:

您已经使用上述方法获得了第一列,因此在第二列中,使用以下公式:

=INDEX(Sheet1!$B$2:$M$102,MATCH(RIGHT(TEXT(Sheet2!A2,"mmm-yyyy"),4)*1,Sheet1!$A$2:$A$102,0),MATCH(LEFT(TEXT(Sheet2!A2,"mmm-yyyy"),3),Sheet1!$B$1:$M$1,0))

根据需要替换范围和/或工作表名称。如果返回#N/A,试试这个:

=INDEX(Sheet1!$B$2:$M$102,MATCH(RIGHT(TEXT(Sheet2!A2,"mmm-yyyy"),4),Sheet1!$A$2:$A$102,0),MATCH(LEFT(TEXT(Sheet2!A2,"mmm-yyyy"),3),Sheet1!$B$1:$M$1,0))

请注意,公式正在使用MATCH()这意味着单元格格式很重要,因此可能无法正常工作。例如,如果 Sheet1 中的年份是文本格式,则第二个公式将起作用;不是第一个,反之亦然。

于 2013-09-20T19:41:35.013 回答