Dec 9, 2008

memo of MS.Excel.VBA II

Purpose
  (I can't remember very exactly so just waiting for rearrangement)

Sub Adachi()
'by Franklin.Q 2008-12-04

Dim RowCt, ColCt, Ct, loopRow, nData, startRow, endRow, startCol, endCol, i As Integer
loopRow = 0
Ct = 0
nData = 0
RowCt = ActiveWorkbook.ActiveSheet.UsedRange.Rows.Count
ColCt = ActiveWorkbook.ActiveSheet.UsedRange.Columns.Count

For Each c In ActiveSheet.Range(Cells(1, 1), Cells(RowCt, 1))
  If Not (c.Value = 0) And Ct = 0 Then
  nData = nData + 1
  End If
  
  If c.Value = 0 Then
    Ct = Ct + 1
  End If
  
  If Ct = 1 Then
  loopRow = loopRow + 1
  End If
Next c
loopRow = loopRow - 1

For i = 1 To Ct
 If i = 1 Then
  startRow = nData + 1
  endRow = startRow + loopRow
  startCol = 1
  endCol = startCol + ColCt - 1
 Else
  Range(Cells(nData + 1, startCol), Cells(nData + 1 + loopRow, endCol)).Value = _
  Range(Cells(startRow, 1), Cells(endRow, ColCt)).Value
  Range(Cells(1, startCol), Cells(1, endCol)).Value = _
  Range(Cells(1, 1), Cells(1, ColCt)).Value
  Range(Cells(startRow, 1), Cells(endRow, ColCt)).ClearContents
End If
 startRow = endRow + 1
 endRow = startRow + loopRow
 startCol = endCol + 1
 endCol = startCol + ColCt - 1
Next i

With ActiveSheet.Range(Cells(nData + 1, 1), Cells(nData + 1 + loopRow, ActiveSheet.UsedRange.Columns.Count)).Select
  Selection.NumberFormatLocal = "0.00E+00"
  Selection.Columns.AutoFit
  
End With

End Sub

No comments: