简体   繁体   English

Excel / VBA-根据位置将多行合并为一-如何检查单元格值,然后将值保存在另一个单元格中?

[英]Excel / VBA - Multiple Rows to One Based on Positioning - How do i check cell value then save the value in another cell?

My excel sheet has value of data in right cell so its like 我的Excel表格在正确的单元格中具有数据的价值,所以它像

+---+--------+---------------------+
|   |   A    |          B          |
+---+--------+---------------------+
| 1 | School | newyork high school |
| 2 | Head   | Mr john             |
| 3 | phone  | 0191919             |
| 4 | email  | john@school.com     |
+---+--------+---------------------+

School name in single cell then others data are next to the cell. 单个单元格中的学校名称,然后其他数据位于该单元格旁边。 I want to arrange them vertically like 我想像垂直排列它们

+---+---------------------+---------+---------+-----------------+
|   |          A          |    B    |    C    |        D        |
+---+---------------------+---------+---------+-----------------+
| 1 | School              | Head    | Phone   | Email           |
| 2 | newyork high school | Mr john | 0191919 | john@school.com |
+---+---------------------+---------+---------+-----------------+

I am trying to get the value of next cell in following way. 我试图通过以下方式获取下一个单元格的值。

Dim cell As Range
For Each cell In Range("a1:a40")
    If cell.Value = school Then
        Range("E3").Value = cell.Offset(1, 0).Value   
Next

It is somewhat unclear exactly what you are trying to accomplish, however, this should get you started: 目前尚不清楚您到底想完成什么,但是,这应该可以帮助您入门:

Sub transposeCellData()
    Dim Rng As Excel.Range
    Dim cll As Excel.Range
    Dim schoolName As String
    Dim schoolHead As String
    Dim schoolAdd As String
    Dim schoolWeb As String
    Dim schoolPhone As String
    Dim schoolFax As String
    Dim outRow As Currency
    outRow = 2
    Set Rng = Range("A1:A40")
    For Each cll In Rng
        If ucase(trim(cll.Value)) = "HEAD:" Then
            schoolName = cll.Offset(-1, 0).Value
            schoolHead = cll.Offset(0, 1).Value
            schoolAdd = cll.Offset(1, 1).Value
            schoolWeb = cll.Offset(2, 1).Value
            schoolPhone = cll.Offset(1, 3).Value
            schoolFax = cll.Offset(2, 3).Value
            Range("I" & outRow).Value = schoolName
            Range("J" & outRow).Value = schoolHead
            Range("K" & outRow).Value = schoolAdd
            Range("L" & outRow).Value = schoolPhone
            Range("M" & outRow).Value = schoolFax
            Range("N" & outRow).Value = schoolWeb
            outRow = outRow + 1
        End If
    Next cll
End Sub

Let me know if that helps. 让我知道是否有帮助。 +1 +1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何检查单元格的内容是否为数组中的值-VBA Excel - How do I check if the contents of a cell is a value in an array - VBA Excel 如何根据 excel 中另一个单元格中的值检查值是否在公差范围内 - How do i check if value is in tolerance based of a value in another cell in excel 使用 VBA 根据另一个单元格值设置 Excel 单元格值 - Setting Excel cell value based on another cell value using VBA 根据单元格值将行从一个 Excel 工作表复制到另一个 - Copying rows from one Excel sheet to another based on cell value 如何创建函数以根据VBA EXCEL中的单元格值隐藏行 - How to create a function to hide rows based on a cell value in VBA EXCEL Excel VBA如何根据不同工作表中单元格的值删除行 - Excel VBA How to delete rows based on the value of a cell in a different worksheet VBA Excel-如何根据另一个单元格的值自动在excel中填充系列? - VBA Excel - How can I automatically fill a series in excel, based on the value of another cell? 如何检查 Excel 单元中 Σ 字符的值? - VBA - How to check the value of Σ character in an Excel Cell? - VBA 如何根据另一个单元格将单元格值限制为最大值? - How do I restrict a cell value to a maximum based on another cell? 如何在Excel 2013 VBA中根据单元格值更改URL值 - How do I change a url value based on a cell value in excel 2013 VBA
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM