VBA,基于指定工作表中的标识符列合并工作表中的表

时间:2018-09-05 10:14:41

标签: vba excel-vba replace

我是VBA的新手。我有两个包含两个表的工作表。工作表1是标题“ Material”下一列的缩写词汇表,以及标题“ Material Description”下一列的说明。表格2是一个数据集,其中包含标题“ Customer Names”下的一列,标题“ Material”下的一列和标题“ Invoiced Values”下的一列。

示例:

The above error occurred in the <t> component:
    in t (created by Message2)
    in Message2 (created by GridListPost1)
    in div (created by t)
    in t (created by GridListPost1)
    in GridListPost1 (created by Channel)
    in div (created by Channel)
    in div (created by Channel)
    in Channel (created by Connect(Channel))
    in Connect(Channel) (created by RouterContext)
    in div (created by App)
    in div (created by App)
    in App (created by Connect(App))
    in Connect(App) (created by RouterContext)
    in RouterContext (created by Router)
    in Router
    in Provider

TypeError: this.props.parent is undefined

所需的输出:

import { XMasonry } from "react-xmasonry";
import Message2 from '../message/Message2'

export default class GridListPost1 extends Component {

  render() {

    const {items} = this.props;

    return (
        <XMasonry>
          {items.map(message => (
            <Message2 key={message.id} message={message}/>
          ))}
        </XMasonry>
    )
  }
}


import { XBlock } from "react-xmasonry";

export default class Message2 extends Component {

  render() {

    const {message} = this.props;

    return (
        <XBlock key={message.id}>
          <div className="card">
                <h1>Wide Card</h1>
                <p>Put any wide text here!</p>
            </div>
        </XBlock>
    )
  }
}       

我正在尝试:

  1. 在各个工作表中查找具有指定标题的列
  2. 对于工作表1的每个行列“材料”,在工作表2中找到与工作表1中相同的“材料”相对应的“材料”
  3. 在工作表2的“材料”列的行中替换文本,在工作表1中将“材料描述”的相应值替换为

对于项目1,我已经了解到了:

Sheet 1      
Material    Material Description
   X               Hot
   B               Cold
   C               Temp
-------------------------------------
Sheet 2       
Material       Invoice Value
   X               2.7645  
   X               3.9
   B               4.6

感谢所有帮助/建议,我希望将其扩展到三个数据集。

1 个答案:

答案 0 :(得分:0)

通过使用以下由Mumps提供的链接中的代码,我可以做到这一点:

https://www.ozgrid.com/forum/forum/help-forums/excel-general/138286-vba-to-join-tables-with-unique-key-in-first-column

Sub CopyRange()
Application.ScreenUpdating = False
Dim LastRow As Long
LastRow = Sheets("OCData").Cells.Find("*", SearchOrder:=xlByRows,      SearchDirection:=xlPrevious).Row
Dim ID As Range
Dim foundID As Range
For Each ID In Sheets("OCData").Range("C2:C" & LastRow)
    Set foundID = Sheets("NamesList").Range("B:B").Find(ID, LookIn:=xlValues, lookat:=xlWhole)
    If Not foundID Is Nothing Then
        Sheets("NamesList").Range("B" & foundID.Row & ":E" & foundID.Row).Copy Sheets("OCData").Range("J" & ID.Row)
    End If
Next ID
Application.ScreenUpdating = True
End Sub

很棒的代码,节省了我很多时间。