将xyz数据输入电子表格

时间:2014-02-01 18:17:36

标签: excel

我在工作表1的3列x,y和z中有Excel数据。这些是具有z值的坐标。我想将z值放在excel电子表格第2页上正确的x,y坐标网格中。例如在x = 2,y = 3,z = 5时,因此片材2的单元格b3中的数据应为5.原始数据包括几个徘徊点。一切都在excel!

2 个答案:

答案 0 :(得分:0)

<强> UPD:

如果您可以确认工作表2上的所有z坐标都有对应的xy(即当您尝试查找z坐标时没有任何情况单元格b3并且在sheet1中没有对x=2y=3,您可以在sheet2上使用此公式:

=SUMPRODUCT((Sheet1!$A:$A=Row())*(Sheet1!$B:$B=Column()),Sheet1!C:C)

否则,如果您无法确认工作表2上的所有z坐标是否对应xy,请使用以下公式:

=IF(COUNTIFS(Sheet1!$A:$A,ROW(),Sheet1!$B:$B,COLUMN()),SUMPRODUCT((Sheet1!$A:$A=ROW())*(Sheet1!$B:$B=COLUMN()),Sheet1!$C:$C),"not found")

在两个公式中,Sheet1!C:C是sheet1上z坐标的地址,Sheet1!A:ASheet1!B:Bxy的地址sheet1上的坐标。

答案 1 :(得分:0)

这项任务最好用VBA进行,如下所示:

Sub Demo()
    Dim wf As WorksheetFunction
    Dim wsSrc As Worksheet
    Dim wsDst As Worksheet
    Dim rSrc As Range
    Dim rdst As Range
    Dim vSrc As Variant
    Dim vDst As Variant
    Dim i As Long

    Set wsSrc = Sheet1
    Set wsDst = Sheet2

    Application.ScreenUpdating = False
    Set wf = Application.WorksheetFunction

    ' Get a reference to the source data
    With wsSrc
        Set rSrc = Range(.Cells(1, 3), .Cells(.Rows.Count, 1).End(xlUp))
    End With

    ' Validate source data
    If wf.Floor(wf.Min(rSrc.Range("1:2")), 1) <= 0 Then
        MsgBox "Invalid data, contains co-ordinates <= 0"
        Exit Sub
    End If

    ' Copy Source to a variant array
    vSrc = rSrc.Value

    ' Prepare Destination sheet
    wsDst.Cells.Clear
    With wsDst
        Set rdst = Range(.Cells(1, 1), .Cells(wf.Max(rSrc.Columns(2)), wf.Max(rSrc.Columns(1))))
    End With

    ' Populate destination sheet
    For i = 1 To UBound(vSrc, 1)
        rdst.Cells(CLng(vSrc(i, 2)), CLng(vSrc(i, 1))) = vSrc(i, 3)
    Next
    Application.ScreenUpdating = True
End Sub

注意,我已经使用了直接写入循环中的目标表而不是Variant数组,这是我通常不会做的。在这种情况下,目标是一个庞大的,人口稀疏的数组。根据max x,y值,这可能导致Out of Memory错误。测试了几个1000个数据点,在几秒钟内运行(OP表示几个100个数据点)