我需要将单元格值传播到一行,这有点难以解释......
我有一个总是要填充二进制值的单元格,例如" 01110011" 数字根据其他公式而变化。 我需要做的是采用相似的相邻值并用它们填充原始...
我认为一张图片胜过千言万语......
http://s28.postimg.org/mf42j9ftp/223.jpg
所以基本上我需要把A1单元格拆分成一行......
我不知道它是怎么做的。
答案 0 :(得分:1)
我认为您会发现LEFT
,RIGHT
和MID
函数很有用。如果您要将所需的所有值(例如01110011
(您用作示例的二进制字符串)放在A
列中,则可以将其拆分为B
列,C
,D
和E
包含以下公式:
专栏B
:
=LEFT($A1,1)
专栏C
:
=MID($A1,2,3)
专栏D
:
=MID($A1,5,2)
专栏E
:
=RIGHT($A1,2)
LEFT
函数将单元格作为第一个参数,并从最左边的字符开始,从该单元格中获取所需的字符数。 RIGHT
函数从最右边的字符执行相同的操作。 MID
函数将单元格作为第一个参数,您希望从第二个参数开始的字符的索引,以及您希望作为第三个参数返回的字符数。
答案 1 :(得分:0)
这应该可以帮到你
Sub splitCell()
Dim cellContent As String
Dim partOfCell As String
Dim columnCounter As Integer
'just to be sure set row format as text to support 00
Rows(2).ClearContents
Rows(2).NumberFormat = "@"
cellContent = CStr(Cells(1, 1))
columnCounter = 1
If Len(cellContent) > 0 Then
partOfCell = Mid(cellContent, 1, 1)
End If
For i = 2 To Len(cellContent)
If Mid(cellContent, i, 1) = Mid(partOfCell, 1, 1) Then
partOfCell = partOfCell + Mid(cellContent, i, 1)
Else
Cells(2, columnCounter) = partOfCell
partOfCell = Mid(cellContent, i, 1)
columnCounter = columnCounter + 1
End If
Next i
Cells(2, columnCounter) = partOfCell
End Sub
答案 2 :(得分:0)
也可以尝试此选项,
Sub ListStringIntoB()
'Loop through string, list characters into Starting B1 and over
Dim str As String, Cnt As Integer, A1 As Range, Lp As Integer
Dim col As Long, Rng As Range, r As Range
Set A1 = Range("A1")
str = A1
Cnt = Len(A1)
For Lp = 1 To Cnt
col = Cells(1, Columns.Count).End(xlToLeft).Column + 1
Set Rng = Cells(1, col)
Rng = Mid(str, Lp, 1)
Next Lp
End Sub
答案 3 :(得分:-1)
感谢各位帮忙,我终于找到了解决困境的答案......我不得不用这段代码来解决问题..
Sub SplitBinaryNumbers()
Dim Bin As Variant
Bin = Application.Transpose(Split(Replace(Replace(Range("A8").Value, "01", "0,1"), "10", "1,0"), ","))
With Range("A20").Resize(UBound(Bin))
.NumberFormat = "@"
.Cells = Bin
End With
End Sub
我希望这有助于某人。