Dreamteam
New Member
- Joined
- Feb 22, 2018
- Messages
- 28
- Office Version
- 365
- Platform
- Windows
Hi
I am trying to loop through worksheets - all with numerical worksheet names and then loop through a range of cells and add some prices. However, I am getting an error each time. I will say though that if I start to run the code when I am actually in one of the relevant worksheets then it completes the task but then can't move on to the next relevant worksheet.
Any help would be much appreciated.
Dt
I am trying to loop through worksheets - all with numerical worksheet names and then loop through a range of cells and add some prices. However, I am getting an error each time. I will say though that if I start to run the code when I am actually in one of the relevant worksheets then it completes the task but then can't move on to the next relevant worksheet.
Any help would be much appreciated.
Dt
Code:
Option Explicit
Sub addprices()
Dim startcell As Range
Dim startrange As Range
Dim ws As Worksheet
Dim wb As Workbook
Set wb = ThisWorkbook
For Each ws In Worksheets
If IsNumeric(ws.Name) Then
Set startcell = ws.Range("d2")
Set startrange = ws.Range("d2", Range("d2").End(xlDown))
For Each startcell In startrange
If startcell = "SWAN MONG" Then
startcell.Offset(0, 1).Value = "12"
Else
If startcell = "COSAWES" Then
startcell.Offset(0, 1).Value = "20"
Else
If startcell = "BASS ACC" Then
startcell.Offset(0, 1).Value = "12"
Else
If startcell = "PL PL SAINS" Then
startcell.Offset(0, 1).Value = "40"
Else
If startcell = "PL PL DRAC" Then
startcell.Offset(0, 1).Value = "19"
Else
If startcell = "TREGEW" Then
startcell.Offset(0, 1).Value = "15"
Else
If startcell = "BERKLEY COTT" Then
startcell.Offset(0, 1).Value = "25"
End If
End If
End If
End If
End If
End If
End If
Next startcell
End If
Next ws
End Sub
Last edited by a moderator: