根据列和行传递数据

时间:2018-02-22 14:54:56

标签: excel vba excel-vba multidimensional-array

我正在尝试将1或0从一张“5s审核”转移到另一张“2月过道分数”根据通过提交按钮执行的通过或失败,问题是我需要的位置传递或未传输到特定单元格取决于日期或区域,如图像(日期/区域)所示,这些是下拉列表。

Sheet1 Date / Area

需要传递给数据的工作表是固定的,具有日期(这是1-31中每一天的数字)作为列和区域作为行。如下图所示。

Sheet2 Data

我试图做的是看看我是否可以使用Dim Statement来启动它,但我不能在生命中找出以哪种方式将区域称为行和日期为列。

我已经设置了从“Dim Loc1 As String”开始的所有Area Cells和从Dim Day1 As Double开始的Days,并参考了每个Cell Location,包括Sheet 1中的前2个Criteria“。

Sub Submit_Button()

Dim Loc1 As String
Dim Loc2 As String
Dim Loc3 As String
Dim Loc4 As String
Dim Loc5 As String
Dim Loc6 As String
Dim Loc7 As String
Dim Loc8 As String
Dim Loc9 As String
Dim Loc10 As String
Dim Loc11 As String
Dim Loc12 As String
Dim Loc13 As String
Dim Loc14 As String
Dim Loc15 As String
Dim Loc16 As String
Dim Loc17 As String
Dim Loc18 As String
Dim Loc19 As String
Dim Loc20 As String
Dim Loc21 As String
Dim Loc22 As String
Dim Loc23 As String
Dim Loc24 As String
Dim Loc25 As String
Dim Loc26 As String
Dim Loc27 As String
Dim Loc28 As String
Dim Loc29 As String
Dim Loc30 As String
Dim Loc31 As String
Dim Loc32 As String
Dim Loc33 As String
Dim Loc34 As String
Dim Loc35 As String
Dim Loc36 As String



Dim Day1 As Double
Dim Day2 As Double
Dim Day3 As Double
Dim Day4 As Double
Dim Day5 As Double
Dim Day6 As Double
Dim Day7 As Double
Dim Day8 As Double
Dim Day9 As Double
Dim Day10 As Double
Dim Day11 As Double
Dim Day12 As Double
Dim Day13 As Double
Dim Day14 As Double
Dim Day15 As Double
Dim Day16 As Double
Dim Day17 As Double
Dim Day18 As Double
Dim Day19 As Double
Dim Day20 As Double
Dim Day21 As Double
Dim Day22 As Double
Dim Day23 As Double
Dim Day24 As Double
Dim Day25 As Double
Dim Day26 As Double
Dim Day27 As Double
Dim Day28 As Double
Dim Day29 As Double
Dim Day30 As Double
Dim Day31 As Double





Dim day As Double
Dim auditor As String
Dim area As String
Dim passorfail As String




day = Sheets("5S Audit").Range("c10").Value
auditor = Sheets("5S Audit").Range("f10").Value
area = Sheets("5S Audit").Range("j10").Value
passorfail = Sheets("5S Audit").Range("p5").Value

'Aisle LOC
Loc1 = Sheets("Feb Aisle Score").Range("B4").Value
Loc2 = Sheets("Feb Aisle Score").Range("B5").Value
Loc3 = Sheets("Feb Aisle Score").Range("B6").Value
Loc4 = Sheets("Feb Aisle Score").Range("B7").Value
Loc5 = Sheets("Feb Aisle Score").Range("B8").Value
Loc6 = Sheets("Feb Aisle Score").Range("B9").Value
Loc7 = Sheets("Feb Aisle Score").Range("B10").Value
Loc8 = Sheets("Feb Aisle Score").Range("B11").Value
Loc9 = Sheets("Feb Aisle Score").Range("B12").Value
Loc10 = Sheets("Feb Aisle Score").Range("B13").Value
Loc11 = Sheets("Feb Aisle Score").Range("B14").Value
Loc12 = Sheets("Feb Aisle Score").Range("B15").Value
Loc13 = Sheets("Feb Aisle Score").Range("B16").Value
Loc14 = Sheets("Feb Aisle Score").Range("B17").Value
Loc15 = Sheets("Feb Aisle Score").Range("B18").Value
Loc16 = Sheets("Feb Aisle Score").Range("B19").Value
Loc17 = Sheets("Feb Aisle Score").Range("B20").Value
Loc18 = Sheets("Feb Aisle Score").Range("B21").Value
Loc19 = Sheets("Feb Aisle Score").Range("B22").Value
Loc20 = Sheets("Feb Aisle Score").Range("B23").Value
Loc21 = Sheets("Feb Aisle Score").Range("B24").Value
Loc22 = Sheets("Feb Aisle Score").Range("B25").Value
Loc23 = Sheets("Feb Aisle Score").Range("B26").Value
Loc24 = Sheets("Feb Aisle Score").Range("B27").Value
Loc25 = Sheets("Feb Aisle Score").Range("B28").Value
Loc26 = Sheets("Feb Aisle Score").Range("B29").Value
Loc27 = Sheets("Feb Aisle Score").Range("B30").Value
Loc28 = Sheets("Feb Aisle Score").Range("B31").Value
Loc29 = Sheets("Feb Aisle Score").Range("B32").Value
Loc30 = Sheets("Feb Aisle Score").Range("B33").Value
Loc31 = Sheets("Feb Aisle Score").Range("B34").Value
Loc32 = Sheets("Feb Aisle Score").Range("B35").Value
Loc33 = Sheets("Feb Aisle Score").Range("B36").Value
Loc34 = Sheets("Feb Aisle Score").Range("B37").Value
Loc35 = Sheets("Feb Aisle Score").Range("B38").Value
Loc36 = Sheets("Feb Aisle Score").Range("B39").Value



'Days
Day1 = Sheets("Feb Aisle Score").Range("C3").Value
Day2 = Sheets("Feb Aisle Score").Range("D3").Value
Day3 = Sheets("Feb Aisle Score").Range("E3").Value
Day4 = Sheets("Feb Aisle Score").Range("F3").Value
Day5 = Sheets("Feb Aisle Score").Range("G3").Value
Day6 = Sheets("Feb Aisle Score").Range("H3").Value
Day7 = Sheets("Feb Aisle Score").Range("I3").Value
Day8 = Sheets("Feb Aisle Score").Range("J3").Value
Day9 = Sheets("Feb Aisle Score").Range("K3").Value
Day10 = Sheets("Feb Aisle Score").Range("L3").Value
Day11 = Sheets("Feb Aisle Score").Range("M3").Value
Day12 = Sheets("Feb Aisle Score").Range("N3").Value
Day13 = Sheets("Feb Aisle Score").Range("O3").Value
Day14 = Sheets("Feb Aisle Score").Range("P3").Value
Day15 = Sheets("Feb Aisle Score").Range("Q3").Value
Day16 = Sheets("Feb Aisle Score").Range("R3").Value
Day17 = Sheets("Feb Aisle Score").Range("S3").Value
Day18 = Sheets("Feb Aisle Score").Range("T3").Value
Day19 = Sheets("Feb Aisle Score").Range("U3").Value
Day20 = Sheets("Feb Aisle Score").Range("V3").Value
Day21 = Sheets("Feb Aisle Score").Range("W3").Value
Day22 = Sheets("Feb Aisle Score").Range("X3").Value
Day23 = Sheets("Feb Aisle Score").Range("Y3").Value
Day24 = Sheets("Feb Aisle Score").Range("Z3").Value
Day25 = Sheets("Feb Aisle Score").Range("AA3").Value
Day26 = Sheets("Feb Aisle Score").Range("AB3").Value
Day27 = Sheets("Feb Aisle Score").Range("AC3").Value
Day28 = Sheets("Feb Aisle Score").Range("AD3").Value
Day29 = Sheets("Feb Aisle Score").Range("AE3").Value
Day30 = Sheets("Feb Aisle Score").Range("AF3").Value
Day31 = Sheets("Feb Aisle Score").Range("AG3").Value


End Sub

帮助将得到极大的赞赏。

Dim mydate As String, myaisle As String, myscore As Integer
Dim i As Long
Dim coord1 As Integer, coord2 As Integer

mydate = Worksheets("5s Audit").Range("C10").Value
myaisle = Worksheets("5s Audit").Range("F10").Value
myscore = Worksheets("Score Transfer").Range("C1").Value

For i = 4 To 39
    If Worksheets("Score Transfer").Cells(i, 1).Value = myaisle Then
        coord1 = i
    End If
Next i

For i = 2 To 32
    If Worksheets("Score Transfer").Cells(3, i).Value = mydate Then
        coord2 = i
    End If
Next i

Worksheets("Score Transfer").Cells(coord1, coord2).Value = myscore
编辑:添加了我的Spreadsheets位置提供的代码dwirony。

1 个答案:

答案 0 :(得分:0)

所以这可以通过将日期和过道值分配给变量,然后在数据表中查找它们来完成。我不得不即兴创作范围,因为你没有将它们包含在你的照片中 - 你必须根据自己的需要改进这些代码。

Sub MoveOneorZero()

Dim mydate As String, myaisle As String, myscore As Integer
Dim i As Long
Dim coord1 As Integer, coord2 As Integer

mydate = Worksheets("Sheet2").Range("C3").Value
myaisle = Worksheets("Sheet2").Range("I3").Value
myscore = Worksheets("Sheet2").Range("H1").Value

For i = 4 To 22
    If Worksheets("Sheet1").Cells(i, 1).Value = myaisle Then
        coord1 = i
    End If
Next i

For i = 2 To 32
    If Worksheets("Sheet1").Cells(3, i).Value = mydate Then
        coord2 = i
    End If
Next i

Worksheets("Sheet1").Cells(coord1, coord2).Value = myscore

End Sub

Sheet1示例:

Sheet1 Example

Sheet2示例:

[Sheet2 Example]

运行宏后:

2 [After running] 3