NicoleJ1987
New Member
- Joined
- Apr 12, 2012
- Messages
- 3
Please help! I am very much a beginner! I am trying to write a code that retrieves information from this sheet entitled "Upload":
A, B, C, D
North America, Florida, Population, 938397.02
North America, Florida, Temperature, 85.04
Africa, Ghana, Population, 829783.50
Africa, Ghana, Temperature, 99.02
North America, Florida, Temperature, 99.20
I want to be able to use VBA to scan the Upload sheet, first for continent (e.g. "North America") - if true - then for State (e.g. "Florida") on the same row - if true - then for "Temperature" on the same row and if that's true also, retrieve number (in this case 99.02) and place it in the sheet entitled "Region" in C3. Also, if there are multiple lines, to sum them.
This is what I pulled together so far, which returns an error of "Compile Error, For without next".
Sub Oval1_Click()
For Each ResultCell In ResultRange
Worksheets("Upload").Activate
Cells.Find(What:="Africa", After:=ActiveCell, LookIn:=xlFormulas, LookAt:= _xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False).Select
If (ActiveCell.Offset(0, 1).Value) = "Ghana" And (ActiveCell.Offset(0, 2).Value) = "Population" Then
ActiveCell.Offset(0, 3).Select
ActiveCell.Copy
Worksheets("Region").Cell("B3").Paste
Application.CutCopyMode = False
End If
End Sub
A, B, C, D
North America, Florida, Population, 938397.02
North America, Florida, Temperature, 85.04
Africa, Ghana, Population, 829783.50
Africa, Ghana, Temperature, 99.02
North America, Florida, Temperature, 99.20
I want to be able to use VBA to scan the Upload sheet, first for continent (e.g. "North America") - if true - then for State (e.g. "Florida") on the same row - if true - then for "Temperature" on the same row and if that's true also, retrieve number (in this case 99.02) and place it in the sheet entitled "Region" in C3. Also, if there are multiple lines, to sum them.
This is what I pulled together so far, which returns an error of "Compile Error, For without next".
Sub Oval1_Click()
For Each ResultCell In ResultRange
Worksheets("Upload").Activate
Cells.Find(What:="Africa", After:=ActiveCell, LookIn:=xlFormulas, LookAt:= _xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False).Select
If (ActiveCell.Offset(0, 1).Value) = "Ghana" And (ActiveCell.Offset(0, 2).Value) = "Population" Then
ActiveCell.Offset(0, 3).Select
ActiveCell.Copy
Worksheets("Region").Cell("B3").Paste
Application.CutCopyMode = False
End If
End Sub
