MS Access 03 - 规范化 Excel 电子表格中的数据

发布于 2024-07-29 05:39:47 字数 431 浏览 6 评论 0原文

我有一个关于分解某些东西的方法的问题。 我收到了这个 Excel 电子表格,它为我提供了制作一份报告所需的数据。 它非常简单明了,但其中有一个特定的部分让我有些悲伤。

在 Excel 电子表格中有一列,其中在一列中列出了“相关方”。 它通常是大约 12 个人的名字,用逗号分隔,但后面还有括号中的 orgID:

joe smith (DIV32)、john doe (DIV12)、roger andrews (DIV14、DIV67、DIV01) 等,

我需要将它们分解为单独的列,以便一旦我将它们导入访问,它们将成为单独的字段。 我知道如何在 Excel 中“文本到列”,但是当 jon doe(DIV13、DIV54 等)有多个分区时,这会搞砸。

不确定如何在访问中执行此操作,但很想知道。

请问有人有excel公式或者访问方法吗?

I have a question about a method to break something apart. I get this Excel spreadsheet that provides me with data that I need to do one report. Its pretty simple and straight forward, however there is one particular part of it that is giving me some grief.

In the Excel spreadsheet there is a column that lists "parties involved" in one column. It usually is about 12 people's names separated by commas, but also has orgID in parenthesis behind it:

joe smith (DIV32), john doe (DIV12), roger andrews (DIV14, DIV67, DIV01), etc

and I need to break these into individual columns so that they will be individual fields once I import them into access. I know how to "text to columns" in Excel, but this get screwed up when jon doe (DIV13, DIV54, etc), has more than one division.

Not sure how to do this in access but would love to know.

Anyone got either an excel formula, or access method for this please?

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

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

发布评论

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

评论(2

空城之時有危險 2024-08-05 05:39:47

我假设您正在将其导入数据库中。 如果没有,那么即使是暂时的,也可能会更容易。 并在每次必须运行报告时重做

您最终将得到三个表来代表这种情况

  1. theParty(人)
  2. theOrganization
  3. thePartyOrg

theParty 有一个 ID 列

theOrganization 将有它自己的 ID 列

thePartyOrder 将有它自己的 ID 列,一个代表政党,一个代表组织

每当您想代表一个政党作为组织的成员时,您必须确保该政党存在/已创建; 组织存在/已创建,然后在 thePartyOrg 表中创建一个指向两者的条目。

由于此连接信息仅作为文本存储在单个列中,因此最简单的方法可能是首先将其全部读入暂存表,然后在 VBA 中解析该列

I assume you are importing this into your database. If not, it is probably easier if you do, even if it's temporary; and redone every time you have to run the report

You are going to end up having three tables to represent this situation

  1. theParty (person)
  2. theOrganisation
  3. thePartyOrg

theParty with have an ID column

theOrganisation will have it's own ID column

thePartyOrder will have it's own ID column, one for theParty, and one for theOrganisation

Whenever you want to represent a Party as bring a member of and Organisation, you have to make sure the Party exists/is created; the Organisation exists/is created, and hen create an entry in the thePartyOrg table which points at both.

Because this connection information just stored as text within a single column, it's probably a easiest to first read it all into a staging table and then parse that column in VBA

风和你 2024-08-05 05:39:47

这是一个解决方案:

我编写了一个函数,用 strReplace 替换所有出现的字符串 strFind,但前提是 strFind 出现在括号内。 因此,您可以将所有“,”字符替换为其他字符(例如“*”),然后将 Excel 的文本运行到列中,然后再次将“*”替换为“,”。

Function replace_paren(strSource As String, strFind As String, strReplace As String) As String
    ' Within strString, replaces any occurrence of strFind with strReplace *IF* strFind occurs within parentheses '

    Dim intOpenParenIndex As Integer
    Dim intCloseParenIndex As Integer

    Do
        intOpenParenIndex = InStr(intCloseParenIndex + 1, strSource, "(")
        intCloseParenIndex = InStr(intOpenParenIndex + 1, strSource, ")")
        If intOpenParenIndex = 0 Then
            Exit Do
        End If

        Mid(strSource, intOpenParenIndex, intCloseParenIndex - intOpenParenIndex) = Replace(Mid(strSource, intOpenParenIndex, intCloseParenIndex - intOpenParenIndex), strFind, strReplace)
    Loop

    replace_paren = strSource

End Function

步骤如下:

1) 将此宏复制到 Excel 工作簿中的模块中

2) 假设您的字符串位于 A 列中。在 B 列中,设置函数来替换逗号,如下所示

=replace_paren(A1,"," ,"*")

3) 在列中填充公式

4) 将列复制并粘贴为值

5) 使用 Excel 的文本到列以使用“,”作为分隔符来解析列

6) 再次使用replace_paren 替换所有出现的“*“ 经过 ”,”

Here's a solution:

I've written a function that replaces all occurrences of a string strFind by strReplace, but only if strFind occurs within parentheses. So you can replace all of the "," characters by something else (e.g. "*"), then run Excel's text to columns, then replace the "*"'s with "," again.

Function replace_paren(strSource As String, strFind As String, strReplace As String) As String
    ' Within strString, replaces any occurrence of strFind with strReplace *IF* strFind occurs within parentheses '

    Dim intOpenParenIndex As Integer
    Dim intCloseParenIndex As Integer

    Do
        intOpenParenIndex = InStr(intCloseParenIndex + 1, strSource, "(")
        intCloseParenIndex = InStr(intOpenParenIndex + 1, strSource, ")")
        If intOpenParenIndex = 0 Then
            Exit Do
        End If

        Mid(strSource, intOpenParenIndex, intCloseParenIndex - intOpenParenIndex) = Replace(Mid(strSource, intOpenParenIndex, intCloseParenIndex - intOpenParenIndex), strFind, strReplace)
    Loop

    replace_paren = strSource

End Function

So the steps are:

1) copy this macro into a module in your Excel workbook

2) Let's say your string is in column A. In column B, set up the function to replace the commas like this

=replace_paren(A1,",","*")

3) Fill the formula down the column

4) Copy and paste the column as values

5) Use Excel's text to columns to parse the column using "," as a delimiter

6) Use replace_paren again to replace all occurrences of "*" by ","

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