Option Explicit
Sub readSheet()
Dim wb As Workbook
Dim settingWs As Worksheet
Dim kind As String
Dim lastRow As Long
Dim lastCol As Long
Dim outputNum As Long
Dim oCount As Long
Set wb = ThisWorkbook
Set settingWs = wb.Sheets("テスト")
lastRow = settingWs.Cells(settingWs.Rows.Count, 1).End(xlToLeft).Row
lastCol = settingWs.Cells(settingWs.Columns.Count, 1).End(xlToLeft).Column
oCount = 0
Dim i As Long
Dim j As Long
For i = 1 To lastRow Step 2
oCount = oCount + 1
For j = 1 To lastCol
kind = settingWs.Cells(i, j)
outputNum = settingWs.Cells(i + 1, j)
OutputData kind, outputNum, oCount
Next j
Next i
End Sub
Sub OutputData(kind As String, outputRowCount As Long, colCount As Long)
Dim wb As Workbook
Dim outputWs As Worksheet
Dim lastRow As Long
Dim outputNum As String
Set wb = ThisWorkbook
Set outputWs = wb.Sheets("output")
lastRow = outputWs.Cells(1, colCount).End(xlToLeft).Row
Select Case True
Case kind Like "待機*"
outputNum = "0"
Case kind Like "走行*"
outputNum = "1"
Case kind Like "急速充電*"
outputNum = "2"
Case kind = "200V充電"
outputNum = "3"
Case kind = "冷却"
outputNum = "4"
End Select
Dim i As Long
For i = 1 To outputRowCount
outputWs.Cells(lastRow, colCount) = outputNum
lastRow = lastRow + 1
Next i
End Sub
Register as a new user and use Qiita more conveniently
- You get articles that match your needs
- You can efficiently read back useful information
- You can use dark theme