投稿日 | : 2003/07/21(Mon) 15:09 |
投稿者 | : Taka |
Eメール | : |
URL | : |
タイトル | : Re^5: スペース区切りで読み込み |
スペース区切りのファイルを読み込み、スペース部分の空白部分に
次のセルのデータを入力し、その次も空白なら次のデータというよ
うにしたいのですが・・・コードは下記のような感じです。
Private Sub Command2_Click()
Dim objFileSystem As Object
Dim objFile As Object
Dim lngLength As Long
Dim count As Integer
Dim FileName As String
Dim Data As String
With Dialog 'データファイルを開く
.DialogTitle = "ファイルを開く"
On Error GoTo BACK
.ShowOpen
FileName = .FileName
End With
count = 1
Set objFileSystem = CreateObject("Scripting.FileSystemObject") '進行状況表示
Set objFile = objFileSystem.GetFile(FileName)
ProgressBar1.Max = objFile.Size
ProgressBar1.Visible = True
Open FileName For Input As #1
Do While Not EOF(1)
Line Input #1, Data
With CellGrid
lngLength = lngLength + LenB(StrConv(Data, vbFromUnicode)) + Len(vbNewLine)
ProgressBar1.Value = lngLength
.Redraw = False
If .Row > .Rows Then
.Row = count
.RowSel = count
.Col = 1
.ColSel = .Cols - 1
Data = Trim(Data) '空白除去
.Clip = Replace(Data, " ", vbTab)
count = count + 1
Else
.Rows = .Rows + 1
.Col = 0 '行番号の表示の追加
.Row = count
.text = count
.CellAlignment = flexAlignCenterCenter
.Row = count
.RowSel = count
.Col = 1
.ColSel = .Cols - 1
Data = Trim(Data) '空白除去
.Clip = Replace(Data, " ", vbTab)
count = count + 1
End If
End With
Loop
Close #1
Set objFileSystem = Nothing
Set objFile = Nothing
CellGrid.Redraw = True
ProgressBar1.Visible = False
MsgBox "ファイルを読み込みました"
BACK:
End Sub
何でも聞いてしまうのはよくないのですが、2日間自分なり
に考えたのですがどうしてもわからないので、どうしたら
空白のセルに次の列のセルを代入してデータが整理できるか
ご教授下さい。お願いします。