Excel – 单列中的string到多列中的字符

我是新的Excel VB。 目前,我想要做以下事情 –

从单元格读取。 像这样的“010111”(二进制)。 可以在表格1中的单元格A10中说明。 写入多个单元格,像这样的信息。 让我们说在表2.单元格B1到B6。 像第2页B1-0第2页B2-1第2页第3页第2页第2页第4页第2页B5-1第2页B6 -1另外,我想使其具有通用性,想要有一个for循环或类似的东西可以做到这一点的dynamic细胞。 即从纸张1-A(i)到纸张2-B(j)到B(j + n)。

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

谢谢,Prateek

这是你如何做到这一点的粗略草图:

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范围,并从第1行开始粘贴到B列。 在这里输入图像说明

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

 'Our first Job is to define the range. 

“我在这里selectD10到K10。 您可以在debugging“行”和“列”的同时检查相同的内容。

Dim rng As Range,cel As Range

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

'定义计数器variables

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

对于每个细胞在rng

 If Len(cel) > 0 Then For i = 1 To Len(cel) 

'从stringCel中提取单个字符

'MID(Input_string,Start_position,Number_of_characters)

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

“决定你想要做什么的价值观

  If char = 0 Then 

'select您要打印的工作表和单元格位置

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

'select要打印的工作表和单元格位置

  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 

下一个细胞

图像中的值仅用于表示,运行代码以查看实际答案

你也可以读一读

从单元格到多个单元格的问候,Patrick Dew

和你的Excel有一个愉快的时光。