|
▼まくら さん:
例えば「みかん 0」の場合はみかんを追加しないということであれば下記で試してみてください。
Sub まくら2()
Dim myStr As String
Dim i As Long, n As Long, lastRow1 As Long, lastRow2 As Long
With ThisWorkbook.Worksheets(3)
lastRow1 = .Range("A" & Rows.Count).End(xlUp).Row
For i = 1 To lastRow1
myStr = .Range("A" & i).Value
n = .Range("B" & i).Value
If n <> 0 Then '=====追加
With ThisWorkbook.Worksheets(4)
lastRow2 = .Range("A" & Rows.Count).End(xlUp).Offset(1).Row
If .Range("A1").Value = "" Then
.Range("A1", "A" & n).Value = myStr
Else
.Range("A" & lastRow2).Resize(n, 1).Value = myStr
End If
End With
End If '=====追加
Next i
End With
End Sub
|
|