Excel从某些单元格中提取数据

发布于 2024-11-11 13:57:33 字数 392 浏览 3 评论 0原文

我有一个文件,我只想在整个文件中以某种模式提取单元格 B9、B19、B29 等。我更希望将其提取到不同的 Excel 文件或以某种方式,以便我可以仅使用另一个 Excel 工作表中的那些单元格进行操作。

潜在地,我可能有几个 Excel 文件,我可能需要做这类事情,所以如果有一种方法可以让我在很多文件中具有相同的格式,我总是可以提取单元格 B9、B19、B29,那就太好了。任何帮助表示感谢,

如果可能的话,我正在寻找语法

编辑

正在思考是否可以以某种方式制作一个excel IF语句说如果行中有一个9并且该行是B然后将其打印在某处但我希望它打印在列中

编辑2 我只想要 B 列,而不是我之前提到的 A 列。 B9、B19、B29、B39 贯穿整个文件

I have a file that I only want to extract cells B9, B19, B29, etc etc etc in a pattern throughout the entire file. I would preferably like it to be extracted to a different excel file or someway so that I can do stuff with only those cells in another excel worksheet.

Potentially, I may have several excel files that I may need to do this sort of thing so if there were a way where I had the same format throughout a lot of files that I could always extract cells B9, B19, B29 that would be great. any help appreciated

I looking for syntax if possible

EDIT

Was thinking if I could somehow make an excel IF statement saying if Row has a 9 in it and the row is B then print it somewhere but I want it printed in a column

EDIT 2
I just want column B not A like I mentioned before.
B9, B19,B29,B39 through the whole file

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

歌枕肩 2024-11-18 13:57:33

以防万一你想用代码来做到这一点:

Sub Test()
  'Assumes Sheet1 has your values and Sheet2 will be the data extracted from every row ending in 9
  Dim iCounter As Long
  Dim newSheetRow As Long
  Dim aValue As String
  Dim bValue As String

  newSheetRow = 1
  'Start and nine and increment by 10 till you reach end of sheet
  For iCounter = 9 To Sheet1.Rows.Count - 1 Step 10 'NOTE:  You may not want to do it by RowCount, but just showing you could
      aValue = Sheet1.Range("A" & iCounter)
      bValue = Sheet1.Range("B" & iCounter)

      Sheet2.Range("A" & newSheetRow).Value = "We were on row: " & iCounter
      Sheet2.Range("B" & newSheetRow).Value = aValue
      Sheet2.Range("C" & newSheetRow).Value = bValue
      newSheetRow = newSheetRow + 1
  Next iCounter

  MsgBox "Done"
End Sub

Just in case you want to do it with code:

Sub Test()
  'Assumes Sheet1 has your values and Sheet2 will be the data extracted from every row ending in 9
  Dim iCounter As Long
  Dim newSheetRow As Long
  Dim aValue As String
  Dim bValue As String

  newSheetRow = 1
  'Start and nine and increment by 10 till you reach end of sheet
  For iCounter = 9 To Sheet1.Rows.Count - 1 Step 10 'NOTE:  You may not want to do it by RowCount, but just showing you could
      aValue = Sheet1.Range("A" & iCounter)
      bValue = Sheet1.Range("B" & iCounter)

      Sheet2.Range("A" & newSheetRow).Value = "We were on row: " & iCounter
      Sheet2.Range("B" & newSheetRow).Value = aValue
      Sheet2.Range("C" & newSheetRow).Value = bValue
      newSheetRow = newSheetRow + 1
  Next iCounter

  MsgBox "Done"
End Sub
め七分饶幸 2024-11-18 13:57:33

您可以使用间接函数。它将单元格引用作为文本字符串并返回该单元格中的值。 而不是使用

=data!a9

来获取单元格 a9 中的工作表“数据”中的值

=indirect("data!a9")

。您还可以使用 r1c1 表示法,如下所示

=indirect("data!r9c1",false)

因此,您可以使用 ROW 和 COLUMN 函数以 10 为步长,

=INDIRECT("data!r"&-1+10*ROW()&"c"&COLUMN(),FALSE)

:输出表 A1 中的公式,然后复制并粘贴它,它将为您提供单元格 A1、A2、A3 中的 data!A9、data!A19、data!A29、... 中的值...具体取决于关于如何如果您希望排列输出,则可能必须修改单元格引用字符串。

You could use the INDIRECT function. It takes a cell reference as a text string and returns the value in that cell. So instead of using

=data!a9

to get the value in sheet "data" in cell a9, you use

=indirect("data!a9")

You can also use r1c1 notation, like this:

=indirect("data!r9c1",false)

From there you can use the ROW and COLUMN functions to go in steps of 10:

=INDIRECT("data!r"&-1+10*ROW()&"c"&COLUMN(),FALSE)

If you put this formula in A1 of your output sheet and then copy and paste it down and across, it will give you the values in data!A9, data!A19, data!A29,... in cells A1, A2, A3... Depending on how you want your output arranged, you might have to modify the cell reference string.

窗影残 2024-11-18 13:57:33

根据您想要执行此操作的频率取决于您需要如何执行此操作,如果是其中之一,一些简单的 Excel 命令可能会有所帮助。

例如,

在单元格 C1 中输入以下内容:

=MOD(ROW(),10)

然后将其复制到数据的底部。该命令将返回数字 1 到 0。然后,您可以过滤 C 列(值为 9)上的数据,然后选择可见行并将数据复制到新工作表。

ROW()  ' this returns the ROW number of cell the command is in.
MOD(number, divisor) ' this basically divides one number by the other and returns the remainder. so row 9 / 10 = 0 remainder of 9, row 19 / 10 = 1 remainder of 9.

希望这有帮助。

Depending on how often you want to do this depends on how you need to do it, if it's a one of them some simple excel commands might help.

e.g.

In Cell C1 put the following:

=MOD(ROW(),10)

then replicate this down to the bottom of your data. the command will return the numbers 1 through to 0. You can then filter the data on column C where value is 9 then select the visible rows and copy the data to a new sheet.

ROW()  ' this returns the ROW number of cell the command is in.
MOD(number, divisor) ' this basically divides one number by the other and returns the remainder. so row 9 / 10 = 0 remainder of 9, row 19 / 10 = 1 remainder of 9.

Hope this helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文