実現したいこと
VBA でcsvファイルを読込み、その値をエクセルのシートにコピーする。(ここまでは調べてできました。)
ファイルを選択した際に、Excelの以前のデータが入っていたらそれを、削除してコピーをしたいのですが、それができません。
例えば、ExcelのA6〜Z30くらいの範囲で、何か値が入っていたら削除してからコピーをしたいです。
以下がExcelのシートをコピーする時に使用しているコードです。
こんな初歩的な質問で大変申し訳ないのですが、
もし可能でしたらアドバイスを頂けますと幸いです。
いつも、ちょっとした事でつまづいてしまいます。。
Sub readBtn_Click() Dim FileType As String Dim FileNamePath As Variant Dim textline, csvline() As String Dim Rowcnt, ColumNum As Integer Dim ch1 As Long Dim inputSheet As Worksheet Set inputSheet = ActiveSheet FileType = "CSV ファイル (*.csv),*.csv" FileNamePath = SelectFileNamePath(FileType) If FileNamePath = False Then End End If ch1 = FreeFile Open FileNamePath For Input As #ch1 On Error GoTo CloseFile Rowcnt = 1 Do While Not EOF(ch1) Line Input #ch1, textline textline = Replace(textline, """", "") csvline() = Split(textline, ",") Range(Cells(Rowcnt + 6, 1), _ Cells(Rowcnt + 6, UBound(csvline()) + 1)) = csvline() Rowcnt = Rowcnt + 1 Loop CloseFile: Close #ch1 End Sub Function GetItemNum(FileNamePath) As Integer Dim ch1 As Long Dim textline As String ch1 = FreeFile Open FileNamePath For Input As #ch1 Line Input #ch1, textlineå Close #ch1 GetItemNum = 1 Do GetItemNum = GetItemNum + 1 textline = Mid(textline, InStr(textline, ",") + 1) Loop Until InStr(textline, ",") = 0 End Function Function SelectFileNamePath(FileType) As Variant SelectFileNamePath = Application.GetOpenFilename(FileType) End Function
回答4件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。