2016-04-21 3 views
0

Я хочу, чтобы моя переменная varJoin записи в каждой из ячеек в столбце A. Таким образом, писать только в 1,1 .... Я надеюсь, что кто-то может помочь мне :)запись в ячейке Excel

Sub extractionMots() 
    Dim Tableau() As String 
    Dim i As Integer 
    Dim res As String 
    Dim ZoneTest As Range 
    Dim ZoneEcrire As Range 
    Dim CelluleSelect As Range 

    Dim arr As Variant 
    Dim varJoin As Variant 

    Set ZoneTest = Range("C1:C16") 
    Set ZoneEcrire = Range("A1:A16") 

     For Each CelluleSelect In ZoneTest 

      ' Suppression des espaces superflus 
      CelluleSelect = Application.WorksheetFunction.Trim(CelluleSelect) 
      res = CelluleSelect.Value 

      Debug.Print res 
      i = 0 
      Tableau() = Split(res, ".") 'découpe la chaine en fonction des points " " 
      'x = Tableau(i) 'le résultat de la fonction Split est stocké dans un tableau 

      For i = 0 To UBound(Tableau) 

       x = Tableau(1) 
       A = Tableau(0) 
       b = Tableau(2) 

       For j = 0 To Len(x) 

        Do While Len(x) < 6 
         x = "0" + x 
        Loop 

        Do While Len(b) < 4 
         b = "0" + b 
        Loop 

       Next j 

      Next i 

     Debug.Print x 

     For c = 0 To Len(ZoneEcire) 

      'define array: 
      arr = Array(A, x, b) 

      'using the vba Join function to join substrings contained in an array: 
        varJoin = Join(arr, ".") 

      'return string after joining the substrings: 
      Cells(c + 1, 1).Value = varJoin 
     Next c 
    Next 

End Sub 

ответ

0

Первый it' потому, что There'sa опечатка в вашем For c ... loop:

You've определил диапазон ZoneEc г гнев, но цикл по ZoneEcire (без г).

Использование опции Explicit защитит от этих опечаток, но это вынудит вас также удалить все другие переменные.

Ниже, что ZoneEcrire является диапазон, и поэтому вы должны цикла

For c = 0 To ZoneEcrire.Count 
0

Спасибо за ваш ответ, но я удалить это Для :) не надо было, и, наконец, мой код выглядит следующим образом:

Sub extractionMots() Dim Tableau() As String Dim я As Integer Dim Рез As String Dim ZoneTest As Range Dim ZoneEcrire Как Range Dim клеточками Избрать Range

Dim arr As Variant 
Dim varJoin As Variant 

Set ZoneTest = Range("C1:C16") 
Set ZoneEcrire = Range("A1:A16") 

For Each CelluleSelect In ZoneTest 

    ' Suppression des espaces superflus 
    CelluleSelect = Application.WorksheetFunction.Trim(CelluleSelect) 
    res = CelluleSelect.Value 

    Debug.Print res 
    i = 0 
    Tableau() = Split(res, ".") 'découpe la chaine en fonction des points " " 
    'x = Tableau(i) 'le résultat de la fonction Split est stocké dans un tableau 

    For i = 0 To UBound(Tableau) 

     x = Tableau(1) 
     A = Tableau(0) 
     b = Tableau(2) 

     For j = 0 To Len(x) 

      Do While Len(x) < 6 
       x = "0" + x 
      Loop 

      Do While Len(b) < 4 
       b = "0" + b 
      Loop 

      'define array: 
      arr = Array(A, x, b) 
      'using the vba Join function to join substrings contained in an array: 
      varJoin = Join(arr, ".") 

     Next j 
    Next i 

    'return string after joining the substrings:' 
    Cells(c + 1, 1).Value = varJoin 
    c = c + 1 
Next 

End Sub

Смежные вопросы