简体   繁体   中英

How to identify table data using merged cells?

I am trying to interpolate a value in the table. However since my column cells are merged together, my code won't read the values. So far whenever i unmerge those columns, it works completely fine and gives me the value i want. How do i integrate merged cells as a matrices?

Sub brent()

Dim i As Integer, j As Integer
Dim P As Single, P1 As Single, P2 As Single
Dim M As Single, M1 As Single, M2 As Single
Dim inputmat()

nrow = 29
ncol = 2

P = Range("Axial").Value

ReDim inputmat(nrow, ncol)

For i = 1 To nrow
    For j = 1 To ncol
    inputmat(i, j) = Cells(5 + i, 6 + j)
    Next j
Next i
If (P > inputmat(1, 1)) Or (P < inputmat(nrow, 1)) Then Range("PM").Value = 
"NG"
Else
    For i = 1 To nrow - 1
       If (P <= inputmat(i, 1)) And (P >= inputmat(i + 1, 1)) Then
          P1 = inputmat(i, 1)
          P2 = inputmat(i + 1, 1)
          M1 = inputmat(i, 2)
          M2 = inputmat(i + 1, 2)
      End If
Next i

For i = 1 To nrow

M = M1 + (P - P1) * (M2 - M1) / (P2 - P1)

Next i

Range("PM").Value = M
End If

End Sub

I know that there is problem under the "input (i,j)= cells(5+i,6+j)" Is there any way to read that black column between the merged cells?

在此处输入图片说明

Sub FindMergedCells()

    Dim tbl As Range, cll As Range
    Dim i As Integer

    i = 1
    Set tbl = Range("A1:E4")

    For Each cll In tbl
        If cll.MergeCells Then
            Cells(i, 7) = "Cell " & cll.Address & " is merged"

            i = i + 1
        End If
    Next

End Sub

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM