G
Guest
I am a new user of VBA (in excel). I must have a huge spreadsheet finished by 3/31 and I was told the only possible way was with VB. I have tried writing some code and keep getting error messages. The spreadsheet has three columns for example
District Amount Scor
7 $10 12
23 $50 22
32 $100 21
There is about 1000 rows with information such as this. I need to be able to go to column 1 (district) and pick up a score in column three with <=200 as one category, the range 201-219 as one category, >=220 as one category, and blank as a category and then pick up and total the amounts that match this criteria in column two. So I will have dollar amounts for the 4 scorebands for each distirct in column 1. (I have 20 different districts)The sheet with the information is named data and I named the ranges with the district numbers "District", with the dollar amounts "Amount", and numerical scores "Score". I was just trying to get one scoreband to work and then I was going to copy it for all the other scorebands (unless there is an easier way). I want one total in cell "02", another in "03", etc. I think one problem is with the Range("District").Value =7. If I change it to just one cell, for instance,"A1" instead of "District", I don't get an error message,but then it adds everything in the amount column and not just <=200. I have worked with this for several days! It seems like it should be simple but.......What I need is similar to a sumif formula such as sumif(A1:A5,"<=200",C1:C5) but I also need to be able to pick up certain districts in the first column! Somebody please help! This is driving me crazy! This is what I tried in VB - and it didn't work..
If (Sheets("DATA").Range("DISTRICT").Value = 7) The
Range("O2").Formula = "=IF(SCORE<=200,SUM(AMOUNT),IF(SCORE=0,0))
End If
End Sub
District Amount Scor
7 $10 12
23 $50 22
32 $100 21
There is about 1000 rows with information such as this. I need to be able to go to column 1 (district) and pick up a score in column three with <=200 as one category, the range 201-219 as one category, >=220 as one category, and blank as a category and then pick up and total the amounts that match this criteria in column two. So I will have dollar amounts for the 4 scorebands for each distirct in column 1. (I have 20 different districts)The sheet with the information is named data and I named the ranges with the district numbers "District", with the dollar amounts "Amount", and numerical scores "Score". I was just trying to get one scoreband to work and then I was going to copy it for all the other scorebands (unless there is an easier way). I want one total in cell "02", another in "03", etc. I think one problem is with the Range("District").Value =7. If I change it to just one cell, for instance,"A1" instead of "District", I don't get an error message,but then it adds everything in the amount column and not just <=200. I have worked with this for several days! It seems like it should be simple but.......What I need is similar to a sumif formula such as sumif(A1:A5,"<=200",C1:C5) but I also need to be able to pick up certain districts in the first column! Somebody please help! This is driving me crazy! This is what I tried in VB - and it didn't work..
If (Sheets("DATA").Range("DISTRICT").Value = 7) The
Range("O2").Formula = "=IF(SCORE<=200,SUM(AMOUNT),IF(SCORE=0,0))
End If
End Sub