2015-08-17 38 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

非常感謝您的回覆。如果我能夠做到我想要的東西,我肯定會試試這個,並提供細節。 –