How to get pack all the nonnull data from a row of

2019-08-08 08:28发布

I have an excel sheet,which has 144 coulms-(4 columns contains one set).i.e 36 sets i do have. Now how can i take out only the Non-Null data from the 2000X350 Excel sheet matrix data,into an 2D array using VBScript?

Here is an Example sheet:

   PID  T1 T1SD T1CD T1ST T2 T2SD T2CD T2ST T3 T3SD T3CD T3ST T4 T4SD T4CD T4ST ........
    10  a   b          b   t             r                     t   k   l     o
    11                     p   p    m    d   n   n    n    b
    .
    .

PID on the column number 11 always.Evey set is comprised of (TN,TNSD,TNCD,TNST) where N=1 to 36. Array will not pick up data into it only iff a set full contains NUll data . Once all the data pick up will be done,it should then relase the data to each row. But thing should be remembered that if 2D array should assign data to the row from where it has been picked up.

Data(1,1)=(a,b,,b,t,,,r,t,k,l,o) During pick up Cell(2,12)=(a,b,,b,t,,,r,t,k,l,o) when releasing the data.

that means data should need to mapped to the correct rows(setwise)

Please let me know if you have any confusion.

EDIT: Output table

    PID  T1 T1SD T1CD T1ST T2 T2SD T2CD T2ST  T3 T3SD T3CD T3ST T4 T4SD T4CD T4ST
    10  a   b          b   t              r    t   k   l     o
    11  p   p    m     d   n   n    n    b

Thanks,Arup

1条回答
叛逆
2楼-- · 2019-08-08 09:31

Here is a partial answer that should get you a nudge in the right direction.

Sub Macro1()

Dim whichT As Integer
Dim whichC As Integer
Dim allNull As Boolean
Dim contents As String

For whichT = 0 to 8 ' this is which T set
  allNull = True
  for whichC = 1 to 4 ' this is which of the 4 elements
    contents = Cells(2, whichT * 4 + whichC + 1)
    Debug.Print "Contents of col ", whichT * 4 + whichC + 1, "are", contents
    If Len(contents) > 0 then allNull = False  ' any one of the non-blank elements sets to False
  Next whichC
  If allNull Then ... ' do some processing to move over the next 4.
Next whichT
End Sub
查看更多
登录 后发表回答