2015-08-17 33 views
1

我是新的Excel VB。目前,我想要做以下操作 -Excel - 单行中的字符串到多列中的字符

从单元格中读取。像这样的“010111”(在Binary中)。让我们在第一张单元格A10中说明它。 向多个单元格写入相同的信息。让我们说在表2.单元格B1到B6。表2 - B1 -0 表2 - B2 -1 表2 - B3 -0 表2 - B4 -1 表2 - B5 -1 表2 - B6 -1 另外,我想使它是通用的,我的意思是我想要一个for循环或类似的东西可以做到这一点动态单元格。即从纸张1-A(i)到纸张2-B(j)到B(j + n)。

请帮我一下吗?这可能从字符串中读取单个字符。我假设我们可以将二进制字符串作为字符串&读取每个字符&然后可以将它们逐个放入列行中,使其对于任何行/列都是动态的。

谢谢 Prateek

+0

可否请您提供一个迄今为止尝试过的代码?如果可能的话连同你的数据样本的屏幕截图。 – psychicebola

+0

不幸的是,我目前无法发布图片。 –

+0

那么你到目前为止的coud请 – psychicebola

回答

0

我找到了答案,更容易理解我自己。无论如何感谢您的所有建议。由于忙于开发该工具,我无法发布回复。这是你们的一小段代码。

'Our first Job is to define the range. 

'这里我选择D10到K10。您可以在调试'&列的行数时检查相同的值。

昏暗RNG作为范围,CEL作为范围

设置RNG =范围( “D10”, “K10”)

“定义计数器变量

昏暗我作为整数,J作为整数

对于每个CEL在RNG

If Len(cel) > 0 Then 

    For i = 1 To Len(cel) 

“提取来自单个字符串切尔

'MID(Input_string,START_POSITION,NUMBER_OF_CHARACTERS)

 char = Mid(cel.Value, i, 1) 

' 决定要与值

 If char = 0 Then 

“您要选择纸张&单元位置做什么打印

  Sheet4.Cells(9 + j, 1).Value = char + " Hey Prateek,Its a Zero" 

     ElseIf char = 1 Then 

'选择工作表要打印

  char = 180 

      Sheet4.Cells(9 + j, 1).Value = char + " Hey Prateek, Its a One" 

     End If 

循环人物&然后增加该行的目的地:“如果你想在其他位置,以及写这

 'oFile.WriteLine Sheet4.Cells(9 + j, 1).Value 

执行此”小区位置

 j = j + 1 

'下一个单元的回路

Next i 

End If 

下一页CEL

The values in the image are just for representation, Run the code to see actual answer

您还可以在

From Cell to multiple cells in Column 问候读取相同, 帕特里克露

有一个愉快的时间与您的Excel。

0

这里是你如何能做到这一点的草图:

Sub test() 
Dim lastRow As Integer, i As Integer, targetCol As Integer, targetRow As Integer 
Dim char As String 
Dim rng As Range, cel As Range 

targetCol = 2 ' Set the target column to col. "B" 
targetRow = 1 ' Set the target Row, starts at row 1 (B1) 

lastRow = Cells(1, 1).End(xlDown).Row 'assuming your data in column A is a bunch of strings you want to break out, without 
    ' any gaps, this will find the last row 

Set rng = Range(Cells(1, 1), Cells(lastRow, 1)) 

For Each cel In rng 
    If Len(cel) > 0 Then 
     For i = 1 To Len(cel) 
      Cells(targetRow + i - 1, targetCol).Value = Mid(cel.Value, i, 1) 
     Next i 
     targetRow = targetRow + Len(cel) 

    End If 
Next cel 


End Sub 

这需要我的A1:A4范围内,并粘贴到上校B,开始第1行: enter image description here

+0

非常感谢您的回复。如果我能够做到我想要的东西,我肯定会试试这个,并提供细节。 –