Hi all,
I'm struggling refining my code after getting some great help on previous posts, i have put together the following code.
The values in CRSInfo sheet are shop names in Col S and Col T has their sales total for the week. The code is designed to go through the range in CRSInfo Col S and store the shop name as 'shop'. It then finds this value in the activesheet (i.e. jan, feb, mar etc) and adds these sales to the sales already in the cell which appear in Col F.
The whole thing works great for me, there are a couple of enhancements i wish to make however, first being the line:
The shop names start at S2, I've put in S100 as there's never usually more than 100 lines, however the code is looping through all the blank cells in this range and putting a £0 in the first blank cell in my activesheet. How do I refer to just the range of cells in CRSInfo?
Full code =
I'm struggling refining my code after getting some great help on previous posts, i have put together the following code.
The values in CRSInfo sheet are shop names in Col S and Col T has their sales total for the week. The code is designed to go through the range in CRSInfo Col S and store the shop name as 'shop'. It then finds this value in the activesheet (i.e. jan, feb, mar etc) and adds these sales to the sales already in the cell which appear in Col F.
The whole thing works great for me, there are a couple of enhancements i wish to make however, first being the line:
Code:
For Each c In Worksheets("CRSInfo").Range("S2:S100")
The shop names start at S2, I've put in S100 as there's never usually more than 100 lines, however the code is looping through all the blank cells in this range and putting a £0 in the first blank cell in my activesheet. How do I refer to just the range of cells in CRSInfo?
Full code =
Code:
Sub crs_add()
Dim c As Range
Dim lastrow1, rng1, lastrow2, rng2, shop, salesthiswk
Dim found
Dim ans
ans = MsgBox("Are You Sure?", vbYesNo + vbExclamation, "Update Sales?")
If ans = vbNo Then Exit Sub
lastrow1 = Worksheets("CRSInfo").Range("S65536").End(xlUp).Row
rng1 = Worksheets("CRSInfo").Range("S1:S1000") 'range of shopnames
For Each c In Worksheets("CRSInfo").Range("S2:S100")
shop = c.Value
salesthiswk = Worksheets("CRSInfo").Cells(c.Row, 20).Value
Set found = Columns("A").Find(what:=shop, lookat:=xlWhole, LookIn:=xlValues)
If Not found Is Nothing Then found.Select
ActiveCell.Offset(0, 5).Value = ActiveCell.Offset(0, 5).Value + salesthiswk
Next c
End Sub