お知恵をお貸しくださいませ。。
■前提・実現したいこと
・csvからVBAで転記をしたい
■発生している問題・エラーメッセージ
・特定のセルのみ「ユーザー定義」に変更される
(転記作業は複数Bookにわたり、そのうち1つの転記元の列がユーザー定義になっている)
・転記元CSVを標準に戻しているつもりだが、転記先のExcel内ではG4セルのみがユーザー定義で表記され
整数で表示したいが日付形式で表示されてしまう
■該当のソースコード
Sub 不支給通知リストに転記_4()
'”C~csv”の” ”の中身をデスクトップのCSV名に書き換える
Workbooks.Open Filename:="C:xxxxxx.csv", ReadOnly:=True
Dim ws, ws1, ws2 As Worksheet
Dim ListLastRow, ListLastRow1, ListLastRow2 As Long
Dim OutputRow1, OutputRow2 As Long
Dim i, x, j, a, b As Long
Set ws = ActiveWorkbook.Worksheets("受付")
Set ws1 = ThisWorkbook.Worksheets("オンライン")
Set ws2 = ThisWorkbook.Worksheets("郵送")
'最終行とる
ListLastRow = ws.Cells(Rows.Count, 1).End(xlUp).Row
ListLastRow1 = ws1.Cells(Rows.Count, "B").End(xlUp).Row
ListLastRow2 = ws2.Cells(Rows.Count, "B").End(xlUp).Row
OutputRow1 = ListLastRow1 + 1
OutputRow2 = ListLastRow2 + 1
ws.Range("PJ:PJ").NumberFormatLocal = "G/標準"
For i = 2 To ListLastRow
If ws.Cells(i, 1) <> "" Then
If ws.Cells(i, 4) = "確認審査完了" Then
If ws.Cells(i, 5) = "郵送" Then
ws2.Cells(OutputRow2, 2) = ws.Cells(i, 3)
ws2.Cells(OutputRow2, 3) = ws.Cells(i, 8)
ws2.Cells(OutputRow2, 4) = ws.Cells(i, 9)
ws2.Cells(OutputRow2, 5) = ws.Cells(i, 19)
ws2.Cells(OutputRow2, 6) = ws.Cells(i, 112)
ws2.Cells(OutputRow2, 7) = ws.Cells(i, 426)
ws2.Cells(OutputRow2, 8) = ws.Cells(i, 427)
ws2.Cells(OutputRow2, 9) = ws.Cells(i, 428)
ws2.Cells(OutputRow2, 10) = ws.Cells(i, 5)
ws2.Cells(OutputRow2, 11) = ws.Cells(i, 434)
OutputRow2 = OutputRow2 + 1
Else ws1.Cells(OutputRow1, 2) = ws.Cells(i, 3) ws1.Cells(OutputRow1, 3) = ws.Cells(i, 8) ws1.Cells(OutputRow1, 4) = ws.Cells(i, 9) ws1.Cells(OutputRow1, 5) = ws.Cells(i, 19) ws1.Cells(OutputRow1, 6) = ws.Cells(i, 112) ws1.Cells(OutputRow1, 7) = ws.Cells(i, 426) ws1.Cells(OutputRow1, 8) = ws.Cells(i, 427) ws1.Cells(OutputRow1, 9) = ws.Cells(i, 428) OutputRow1 = OutputRow1 + 1 End If End If
End If
Next i
ListLastRow1 = ws1.Cells(Rows.Count, "B").End(xlUp).Row
ListLastRow2 = ws2.Cells(Rows.Count, "B").End(xlUp).Row
ws1.Range("G:G").NumberFormatLocal = "G/標準"
ws2.Range("G:G").NumberFormatLocal = "G/標準"
For x = 4 To ListLastRow1
ws1.Cells(x, 7) = Replace(ws1.Cells(x, 7), "44867", "11-2")
ws1.Cells(x, 7) = Replace(ws1.Cells(x, 7), "44610", "18-2")
ws1.Cells(x, 7) = Replace(ws1.Cells(x, 7), "44576", "15-1")
ws1.Cells(x, 7) = Replace(ws1.Cells(x, 7), "44652", "4-1")
ws1.Cells(x, 7) = Replace(ws1.Cells(x, 7), "2022/4/1", "4-1")
Next x
For j = 4 To ListLastRow2
ws2.Cells(j, 7) = Replace(ws2.Cells(j, 7), "44867", "11-2")
ws2.Cells(j, 7) = Replace(ws2.Cells(j, 7), "44610", "18-2")
ws2.Cells(j, 7) = Replace(ws2.Cells(j, 7), "44576", "15-1")
ws2.Cells(x, 7) = Replace(ws2.Cells(x, 7), "44652", "4-1")
ws2.Cells(x, 7) = Replace(ws2.Cells(x, 7), "2022/4/1", "4-1")
Next j
ListLastRow1 = ws1.Cells(Rows.Count, "B").End(xlUp).Row
For a = 2 To ListLastRow
If ws.Cells(a, 7) = "2022/4/1" Or ws.Cells(a, 7) = "44652" Then
ws.Cells(a, 7) = ""
End If
Next
'CSV閉じる
ActiveWorkbook.Close SaveChanges:=False
End Sub
■自分で調べたことや試したこと
・標準におきかえるコードや置換コードは入れてみています
∟ただしG4セルのみ置換が反映されません
回答1件
あなたの回答
tips
プレビュー