Get the same results in the attached first pic - excel

Pic 2 shows what the solution should be and Pic 1 shows what my code has given me, the differences occur in the "Yearly Change","Percent Change" and "Total Stock Volume" columns.
The loop I created works for all the sheets but my figures in those specified column are off, can I get help in rectifying my code attached to get numbers similar to Pic 2? Thank you
Option Explicit
Sub Stockmarket()
'Declare and set worksheet
Dim ws As Worksheet
'Loop through all stocks for one year
For Each ws In Worksheets
'Create the column headings
ws.Range("I1").Value = "Ticker"
ws.Range("J1").Value = "Yearly Change"
ws.Range("K1").Value = "Percent Change"
ws.Range("L1").Value = "Total Stock Volume"
ws.Range("P1").Value = "Ticker"
ws.Range("Q1").Value = "Value"
ws.Range("O2").Value = "Greatest % Increase"
ws.Range("O3").Value = "Greatest % Decrease"
ws.Range("O4").Value = "Greatest Total Volume"
'Define Ticker variable
Dim Ticker As String
'Set initial and last row for worksheet
Dim Lastrow As Long
Dim i As Long
Dim j As Integer
Dim x As Double
j = 2
x = 2
'Define Lastrow of worksheet
Lastrow = ws.Cells(Rows.Count, 1).End(xlUp).Row
'Set new variables for prices and percent changes
Dim open_price As Double
'open_price = 0
Dim close_price As Double
'close_price = 0
Dim price_change As Double
'price_change = 0
Dim price_change_percent As Double
'price_change_percent = 0
'Create variable to keep the ticker row in
Dim TickerRow As Long
TickerRow = 1
Dim stock_volume As Double
stock_volume = 0
'Do loop of current worksheet to Lastrow
For i = 2 To Lastrow
'Ticker symbol output
If ws.Cells(i + 1, 1).Value <> ws.Cells(i, 1).Value Then
TickerRow = TickerRow + 1
Ticker = ws.Cells(i, 1).Value
ws.Cells(TickerRow, "I").Value = Ticker
'Stock Volume output
If ws.Cells(i, 1).Value = ws.Cells(i + 1, 1).Value Then
stock_volume = stock_volume + ws.Cells(i, 7).Value
ElseIf ws.Cells(i, 1).Value <> Cells(i + 1, 1).Value Then
stock_volume = stock_volume + ws.Cells(i, 7).Value
ws.Cells(j, 9).Value = ws.Cells(i, 1).Value
ws.Cells(j, 12).Value = stock_volume
j = j + 1
stock_volume = 0
End If
'Creating the Yearly change and Percent change output
open_price = ws.Cells(i, 3).Value
close_price = ws.Cells(i, 6).Value
ws.Cells(x, 10).Value = open_price - close_price
If close_price <= 0 Then
ws.Cells(x, 11).Value = 0
Else
ws.Cells(x, 11).Value = (close_price / open_price) - 1
End If
ws.Cells(x, 11).Style = "Percent"
If ws.Cells(x, 10).Value >= 0 Then
ws.Cells(x, 10).Interior.ColorIndex = 4
Else
ws.Cells(x, 10).Interior.ColorIndex = 3
End If
x = x + 1
ws.Cells(x, 9).Value = ws.Cells(i, 1).Value
ws.Cells(x, 10).Value = close_price - open_price
If close_price <= 0 Then
ws.Cells(x, 11).Value = 0
Else
ws.Cells(x, 11).Value = (close_price / open_price) - 1
End If
ws.Cells(x, 11).Style = "Percent"
If ws.Cells(x, 10).Value >= 0 Then
ws.Cells(x, 10).Interior.ColorIndex = 4
Else
ws.Cells(x, 10).Interior.ColorIndex = 3
End If
End If
Next i
Next ws
End Sub

You seem to have a logic problem - see the two marked lines below
'Ticker symbol output
If ws.Cells(i + 1, 1).Value <> ws.Cells(i, 1).Value Then '<<<<<<<<<
TickerRow = TickerRow + 1
Ticker = ws.Cells(i, 1).Value
ws.Cells(TickerRow, "I").Value = Ticker
'Stock Volume output
If ws.Cells(i, 1).Value = ws.Cells(i + 1, 1).Value Then '<<< never true!
stock_volume = stock_volume + ws.Cells(i, 7).Value
ElseIf ws.Cells(i, 1).Value <> Cells(i + 1, 1).Value Then
stock_volume = stock_volume + ws.Cells(i, 7).Value
ws.Cells(j, 9).Value = ws.Cells(i, 1).Value
ws.Cells(j, 12).Value = stock_volume
j = j + 1
stock_volume = 0
End If

Related

Editing Excel from Access VBA Object Required Error

I have a program that opens an Excel spreadsheet and makes changes to it. I am always editing the first sheet but if it is a certain type of report I want to edit the second sheet as well. This all works fine for me on the first sheet and all but centering the text in the cell on the second sheet. I get an Object Required error only when I try to do this. I center the text in the cells on the first sheet no problem. The error only comes after I pass the object to the new procedure. Here is some of my code:
First Procedure
Private Sub OSummary1(strfile As String, strTableResults As String, dtUnivDt As Date)
Dim xlApp As Object
Dim objWorkbook As Object
Dim objSheet As Object
Set xlApp = CreateObject("Excel.Application")
Set objWorkbook = xlApp.Workbooks.Open(strfile)
Set objSheet = objWorkbook.Sheets(1)
Later in the code
ElseIf Mid(strTableResults, 11, 1) = 1 Then
Max = 11
Do Until i > Max
If .Cells(i, 4).Value = "0" And .Cells(i, 2).Value = "0" And .Cells(i, 3).Value = "0" Then
.Cells(i, 4).Value = "NA"
.Cells(i, 4).Interior.ColorIndex = 15
.Cells(i, 3).Value = "-"
.Cells(i, 2).Value = "-"
ElseIf .Cells(i, 2).Value = "0" Then
.Cells(i, 4).Value = "0.0"
.Cells(i, 4).Interior.ColorIndex = 22
ElseIf .Cells(i, 4).Value >= "95.00" Or .Cells(i, 4).Value = "100" Then
.Cells(i, 4).Interior.ColorIndex = 43
ElseIf .Cells(i, 4).Value >= "90.00" And .Cells(i, 4).Value < "95.00" Then
.Cells(i, 4).Interior.ColorIndex = 36
Else
.Cells(i, 4).Interior.ColorIndex = 22
End If
If .Cells(i, 4).Value = 0 Then
.Cells(i, 4).NumberFormat = "0.00%"
ElseIf Not .Cells(i, 4).Value Like "*.*" Then
.Cells(i, 4).NumberFormat = "#.00""%"""
ElseIf .Cells(i, 4).Value Like "*.#" Then
.Cells(i, 4).NumberFormat = "#.#0""%"""
Else
.Cells(i, 4).NumberFormat = "#.##""%"""
End If
If .Cells(i, 1).Value = "AppealNotificationTimeliness" Then
.Cells(i, 1).Font.Bold = True
.Cells(i, 2).Font.Bold = True
.Cells(i, 3).Font.Bold = True
.Cells(i, 4).Font.Bold = True
.Cells(i, 2).HorizontalAlignment = xlCenter
.Cells(i, 3).HorizontalAlignment = xlCenter
.Cells(i, 4).HorizontalAlignment = xlCenter
iB = Len(.Cells(i, 2).Value)
iC = Len(.Cells(i, 3).Value)
iD = .Cells(i, 4).Value
Else
'Indent header
.Cells(i, 1).IndentLevel = 3
'Indent sub-headers
If iB < 3 Then
.Cells(i, 2).IndentLevel = 5
ElseIf iB > 2 And iB < 5 Then
.Cells(i, 2).IndentLevel = 4
ElseIf iB > 4 And iB < 7 Then
.Cells(i, 2).IndentLevel = 3
Else
.Cells(i, 2).IndentLevel = 2
End If
If iC < 3 Then
.Cells(i, 3).IndentLevel = 4
ElseIf iC > 2 And iC < 5 Then
.Cells(i, 3).IndentLevel = 3
ElseIf iC > 4 And iC < 7 Then
.Cells(i, 3).IndentLevel = 2
Else
.Cells(i, 3).IndentLevel = 1
End If
If iD = "NA" Then
.Cells(i, 4).IndentLevel = 5
ElseIf iD = "100" Then
.Cells(i, 4).IndentLevel = 3
Else
.Cells(i, 4).IndentLevel = 4
End If
End If
i = i + 1
Loop
If Right(strTableResults, 3) = "FDR" Then
Call FDRTable1(objWorkbook)
End If
This all works fine for sheet 1
Second Procedure from Call above
Private Sub FDRTable1(ByRef objWorkbook As Object)
Dim objSheet As Object
Dim RowCnt As Integer
Dim CurrentRow As Integer
Dim CurrentRowVal As String
Dim iRange As Range
Dim iCells As Range
Dim i As Integer
Dim Max As Integer
Set objSheet = objWorkbook.Sheets(2)
i = 2
With objSheet
'Header
.Cells(1, 1).Font.Size = 12
.Range("A1:G1").Font.Bold = True
.Cells.EntireColumn.AutoFit
.Range("A2:G6").BorderAround LineStyle:=xlContinuous, Weight:=xlMedium
.Range("A7:G9").BorderAround LineStyle:=xlContinuous, Weight:=xlMedium
.Range("A10:G14").BorderAround LineStyle:=xlContinuous, Weight:=xlMedium
.Range("A15:G17").BorderAround LineStyle:=xlContinuous, Weight:=xlMedium
Max = 17
Do Until i > Max
If .Cells(i, 7).Value = "0" And .Cells(i, 4).Value = "0" And .Cells(i, 6).Value = "0" Then
.Cells(i, 7).Value = "NA"
.Cells(i, 7).Interior.ColorIndex = 15
.Cells(i, 4).Value = "-"
.Cells(i, 5).Value = "-"
.Cells(i, 6).Value = "-"
ElseIf .Cells(i, 4).Value = "0" Then
.Cells(i, 7).Value = "0.0"
.Cells(i, 7).Interior.ColorIndex = 22
ElseIf .Cells(i, 7).Value >= "95.00" Or .Cells(i, 7).Value = "100" Then
.Cells(i, 7).Interior.ColorIndex = 43
ElseIf .Cells(i, 7).Value >= "90.00" And .Cells(i, 7).Value < "95.00" Then
.Cells(i, 7).Interior.ColorIndex = 36
Else
.Cells(i, 7).Interior.ColorIndex = 22
End If
If .Cells(i, 7).Value = 0 Then
.Cells(i, 7).NumberFormat = "0.00%"
.Cells(i, 4).HorizontalAlignment.xlCenter
.Cells(i, 5).HorizontalAlignment.xlCenter
.Cells(i, 6).HorizontalAlignment.xlCenter
.Cells(i, 7).HorizontalAlignment.xlCenter
ElseIf Not .Cells(i, 7).Value Like "*.*" Then
.Cells(i, 7).NumberFormat = "#.00""%"""
.Cells(i, 4).HorizontalAlignment.xlCenter
.Cells(i, 5).HorizontalAlignment.xlCenter
.Cells(i, 6).HorizontalAlignment.xlCenter
.Cells(i, 7).HorizontalAlignment.xlCenter
ElseIf .Cells(i, 7).Value Like "*.#" Then
.Cells(i, 7).NumberFormat = "#.#0""%"""
.Cells(i, 4).HorizontalAlignment.xlCenter
.Cells(i, 5).HorizontalAlignment.xlCenter
.Cells(i, 6).HorizontalAlignment.xlCenter
.Cells(i, 7).HorizontalAlignment.xlCenter
Else
.Cells(i, 7).NumberFormat = "#.##""%"""
.Cells(i, 4).HorizontalAlignment.xlCenter
.Cells(i, 5).HorizontalAlignment.xlCenter
.Cells(i, 6).HorizontalAlignment.xlCenter
.Cells(i, 7).HorizontalAlignment.xlCenter
End If
i = i + 1
Loop
End With
End Sub
This all works too except I get the error when I try to center the text (.HorizontalAlignment.xlCenter). If I remove those lines, it works fine.

Populate listbox with headers

I am trying to populate a listbox from a list of items, I can get it to populate but it is taking in my header row as a row in the list and the headers are blank. I am not sure where I am going wrong. Any help would be great.
Sub populateList()
Dim rngName As Range
Dim ws As Worksheet
Dim i As Integer
Set ws = Worksheets("ProjectData")
lbTasks.Clear
lbTasks.ColumnHeads = True
lbTasks.ColumnCount = 10
Dim LastRow As Long
LastRow = ws.Cells(ws.Rows.Count, 1).End(xlUp).Row
For i = 1 To LastRow
If ws.Cells(i, 1).Value <> vbNullString Then lbTasks.AddItem ws.Cells(i, 1).Value
If ws.Cells(i, 2).Value <> vbNullString Then lbTasks.List(i - 1, 1) = ws.Cells(i, 2).Value
If ws.Cells(i, 3).Value <> vbNullString Then lbTasks.List(i - 1, 2) = ws.Cells(i, 3).Value
If ws.Cells(i, 4).Value <> vbNullString Then lbTasks.List(i - 1, 3) = ws.Cells(i, 4).Value
If ws.Cells(i, 5).Value <> vbNullString Then lbTasks.List(i - 1, 4) = ws.Cells(i, 5).Value
If ws.Cells(i, 6).Value <> vbNullString Then lbTasks.List(i - 1, 5) = ws.Cells(i, 6).Value
If ws.Cells(i, 7).Value <> vbNullString Then lbTasks.List(i - 1, 6) = ws.Cells(i, 7).Value
If ws.Cells(i, 8).Value <> vbNullString Then lbTasks.List(i - 1, 7) = ws.Cells(i, 8).Value
If ws.Cells(i, 9).Value <> vbNullString Then lbTasks.List(i - 1, 8) = ws.Cells(i, 9).Value
If ws.Cells(i, 10).Value <> vbNullString Then lbTasks.List(i - 1, 9) = ws.Cells(i, 10).Value
Next i
End Sub

Error 381 populating listbox from a sheet table

I am getting all the time error 381.. What is there wrong? If i use only 1 column it works, if i add 2nd and more it stops working.
I try to populate my rows which compile with "if statement".
it stops each time to work at 2nd column.
UserForm + some Data:
https://drive.google.com/open?id=1hfCAu2m7C4kISSPJSvyjWc-TvxBr-fOO
2nd Version of code:
Sub PopulateList2()
Dim rngName As Range
Dim ws As Worksheet
Dim i As Integer
Dim LastRow As Long
Set ws = E1G
With ListBoxAbg
.Clear
.ColumnCount = 2
LastRow = ws.Cells(ws.Rows.Count, 1).End(xlUp).row
For i = 1 To LastRow
If ws.Cells(i, 6).Value < Now() _
And ws.Cells(i, 6).Value <> vbNullString Then
.AddItem
.List(i - 1, 0) = ws.Cells(i, 1).Value
.List(i - 1, 1) = ws.Cells(i, 3).Value
End If
Next i
End With
End Sub
....
Sub PopulateList2()
Dim rngName As Range
Dim ws As Worksheet
Dim i As Integer
Dim LastRow As Long
Set ws = E1G
AbgeListField.Clear
AbgeListField.ColumnCount = 7
LastRow = ws.Cells(ws.Rows.Count, 1).End(xlUp).row
For i = 1 To LastRow
If ws.Cells(i, 6).Value < Now() _
And ws.Cells(i, 6).Value <> vbNullString Then
AbgeListField.AddItem ws.Cells(i, 1).Value
AbgeListField.List(i - 1, 1) = ws.Cells(i, 2).Value
AbgeListField.List(i - 1, 2) = ws.Cells(i, 3).Value
AbgeListField.List(i - 1, 3) = ws.Cells(i, 4).Value
AbgeListField.List(i - 1, 4) = ws.Cells(i, 5).Value
AbgeListField.List(i - 1, 5) = ws.Cells(i, 6).Value
AbgeListField.List(i - 1, 6) = ws.Cells(i, 7).Value
End If
Next i
End Sub
i found the answer in that post:
https://social.msdn.microsoft.com/Forums/office/en-US/f5619db9-be72-41e3-a353-54ebb021f936/runtime-error-381-could-not-set-the-list-property-invalid-property-array-index?forum=exceldev
i added new dim nxtItme As Long. it works perfect now:
Sub PopulateList2()
Dim rngName As Range
Dim ws As Worksheet
Dim i As Integer
Dim LastRow As Long
Dim nxtItem As Long
Set ws = E1G
nxtItem = 0
With ListBoxAbg
.Clear
.ColumnCount = 6
LastRow = ws.Cells(ws.Rows.Count, 1).End(xlUp).row
For i = 1 To LastRow
If ws.Cells(i, 6).Value < Now() _
And ws.Cells(i, 6).Value <> vbNullString Then
.AddItem
.List(nxtItem, 0) = ws.Cells(i, 1).Value
.List(nxtItem, 1) = ws.Cells(i, 3).Value
.List(nxtItem, 2) = ws.Cells(i, 4).Value
.List(nxtItem, 3) = ws.Cells(i, 5).Value
.List(nxtItem, 4) = ws.Cells(i, 6).Value
nxtItem = nxtItem + 1
End If
Next i
End With
End Sub

Excel based tracking database

I have a code which Sheet "RAW" is updated each day with more rows and updates the existing rows, I'm trying to get the number in Column B to match Column A in sheet data, then depending on what information is in other columns add 1 to a value in a column (17 different options)
It's basically going to be used as a tracker to check how many days something is on a specific status and I need to keep it for historical Measuring indefintely. here is what I have so far which doesn't seem to work.
Additionally I would also like it to measure an 18th catagory if it is missing from the data list if this is possibble?
'status tracking
Sub Status_Track()
Dim a As Long 'topic number
Dim Z As Long
Dim R As Long
Dim i As Long
Dim S As Long
Dim D As Long
Worksheets("RAW").Activate
R = Cells(Rows.Count, 2).End(xlUp).Row
C = Cells(1, Columns.Count).End(xlToLeft).Column
Z = 0
i = 2
Do Until i > R
'ident
If Cells(i, 2) = Worksheets("Data").Cells(i, 1) And (Cells(i, 13) = "ERKA") Then
Z = Worksheets("Data").Cells(i, 6) + 1
Worksheets("Data").Cells(i, 6).Value = Z
ElseIf Cells(i, 2) = Worksheets("Data").Cells(i, 1) And (Cells(i, 13) = "INBA") Then
'Inba
Z = Worksheets("Data").Cells(i, 7) + 1
Worksheets("Data").Cells(i, 7).Value = Z
ElseIf Cells(i, 2) = Worksheets("Data").Cells(i, 1) And (Cells(i, 13) = "ABGE") Then
'Abge
Z = Worksheets("Data").Cells(i, 8) + 1
Worksheets("Data").Cells(i, 8).Value = Z
ElseIf Cells(i, 2) = Worksheets("Data").Cells(i, 1) And (Cells(i, 13) = "GELO") Then
'Gelo
Z = Worksheets("Data").Cells(i, 5) + 1
Worksheets("Data").Cells(i, 5).Value = Z
ElseIf Cells(i, 2) = Worksheets("Data").Cells(i, 1) And (Cells(i, 13) = "UEBE") And (Cells(i, 11) = 0) Then
'UEBE
Z = Worksheets("Data").Cells(i, 9) + 1
Worksheets("Data").Cells(i, 9).Value = Z
ElseIf Cells(i, 11) = 1 And (Cells(i, 28) = "<1") Then
'1
Z = Worksheets("Data").Cells(i, 10) + 1
Worksheets("Data").Cells(i, 10).Value = Z
ElseIf Cells(i, 11) = 1 And (Cells(i, 28) = "6") Then
'6
Z = Worksheets("Data").Cells(i, 11) + 1
Worksheets("Data").Cells(i, 11).Value = Z
ElseIf Cells(i, 11) = 1 And (Cells(i, 28) = "9") Then
'9
Z = Worksheets("Data").Cells(i, 12) + 1
Worksheets("Data").Cells(i, 12).Value = Z
ElseIf Cells(i, 11) = 1 And (Cells(i, 28) = "10") Then
'10
Z = Worksheets("Data").Cells(i, 13) + 1
Worksheets("Data").Cells(i, 13).Value = Z
ElseIf Cells(i, 11) = 1 And (Cells(i, 28) = "15") Then
'15
Z = Worksheets("Data").Cells(i, 14) + 1
Worksheets("Data").Cells(i, 14).Value = Z
ElseIf Cells(i, 11) = 1 And (Cells(i, 28) = "30") Then
'30
Z = Worksheets("Data").Cells(i, 15) + 1
Worksheets("Data").Cells(i, 15).Value = Z
ElseIf Cells(i, 11) = 1 And (Cells(i, 28) = "50") Then
'50
Z = Worksheets("Data").Cells(i, 16) + 1
Worksheets("Data").Cells(i, 16).Value = Z
ElseIf Cells(i, 11) = 1 And (Cells(i, 28) = "60") Then
'60
Z = Worksheets("Data").Cells(i, 17) + 1
Worksheets("Data").Cells(i, 17).Value = Z
ElseIf Cells(i, 11) = 1 And (Cells(i, 28) = "70") Then
'70
Z = Worksheets("Data").Cells(i, 18) + 1
Worksheets("Data").Cells(i, 18).Value = Z
ElseIf Cells(i, 11) = 1 And (Cells(i, 28) = "80") Then
'80
Z = Worksheets("Data").Cells(i, 19) + 1
Worksheets("Data").Cells(i, 19).Value = Z
ElseIf Cells(i, 11) = 1 And (Cells(i, 28) = "90") Then
'90
Z = Worksheets("Data").Cells(i, 20) + 1
Worksheets("Data").Cells(i, 20).Value = Z
ElseIf Cells(i, 11) = 1 And (Cells(i, 28) = "97") Then
'97
Z = Worksheets("Data").Cells(i, 21) + 1
Worksheets("Data").Cells(i, 21).Value = Z
ElseIf Cells(i, 11) = 1 And (Cells(i, 28) = "100") Then
'100
Z = Worksheets("Data").Cells(i, 22) + 1
Worksheets("Data").Cells(i, 22).Value = Z
End If
Loop
End Sub
It could look something like that to find the corresponding identifier
Option Explicit 'must be the first line in a module: forces you to declare any variables before use
'status tracking
Sub Status_Track_Extended()
Dim wsRaw As Worksheet, wsData As Worksheet
Set wsRaw = ThisWorkbook.Worksheets("RAW")
Set wsData = ThisWorkbook.Worksheets("Data")
Dim LastRow As Long
LastRow = wsRaw.Cells(wsRaw.Rows.Count, 2).End(xlUp).Row 'find last row in sheet RAW
Dim FoundCell As Range, FoundRow As Long
Dim DataCol As Long
Dim i As Long
For i = 2 To LastRow 'start at row 2 up to last used row
'find corresponding row by identifier (column 2) in sheet Data
Set FoundCell = wsData.Columns(1).Find(wsRaw.Cells(i, 2))
If Not FoundCell Is Nothing Then 'only do the follwing if the identifier was found in sheet Data
FoundRow = FoundCell.Row
'ident
If wsRaw.Cells(i, 13) = "ERKA" Then
wsData.Cells(FoundRow, 6).Value = wsData.Cells(FoundRow, 6).Value + 1
ElseIf wsRaw.Cells(i, 13) = "INBA" Then
'Inba
wsData.Cells(FoundRow, 7).Value = wsData.Cells(FoundRow, 7).Value + 1
ElseIf wsRaw.Cells(i, 13) = "ABGE" Then
'Abge
wsData.Cells(FoundRow, 8).Value = wsData.Cells(FoundRow, 8).Value + 1
ElseIf wsRaw.Cells(i, 13) = "GELO" Then
'Gelo
wsData.Cells(FoundRow, 5).Value = wsData.Cells(FoundRow, 5).Value + 1
ElseIf wsRaw.Cells(i, 13) = "UEBE" And wsRaw.Cells(i, 11) = 0 Then
'UEBE
wsData.Cells(FoundRow, 9).Value = wsData.Cells(FoundRow, 9).Value + 1
ElseIf wsRaw.Cells(i, 11) = 1 Then
Select Case wsRaw.Cells(i, 28)
Case "<1"
wsData.Cells(FoundRow, 10).Value = wsData.Cells(FoundRow, 10).Value + 1
Case "6"
wsData.Cells(FoundRow, 11).Value = wsData.Cells(FoundRow, 11).Value + 1
Case "9"
wsData.Cells(FoundRow, 12).Value = wsData.Cells(FoundRow, 12).Value + 1
Case "10"
wsData.Cells(FoundRow, 13).Value = wsData.Cells(FoundRow, 13).Value + 1
Case "15"
wsData.Cells(FoundRow, 14).Value = wsData.Cells(FoundRow, 14).Value + 1
Case "30"
wsData.Cells(FoundRow, 15).Value = wsData.Cells(FoundRow, 15).Value + 1
Case "50"
wsData.Cells(FoundRow, 16).Value = wsData.Cells(FoundRow, 16).Value + 1
Case "60"
wsData.Cells(FoundRow, 17).Value = wsData.Cells(FoundRow, 17).Value + 1
Case "70"
wsData.Cells(FoundRow, 18).Value = wsData.Cells(FoundRow, 18).Value + 1
Case "80"
wsData.Cells(FoundRow, 19).Value = wsData.Cells(FoundRow, 19).Value + 1
Case "90"
wsData.Cells(FoundRow, 20).Value = wsData.Cells(FoundRow, 20).Value + 1
Case "97"
wsData.Cells(FoundRow, 21).Value = wsData.Cells(FoundRow, 21).Value + 1
Case "100"
wsData.Cells(FoundRow, 22).Value = wsData.Cells(FoundRow, 22).Value + 1
End Select
End If
Else 'error if identifier was not found
MsgBox "Identifier '" & wsRaw.Cells(i, 2) & "' could not be found in sheet 'Data'.", vbExclamation + vbOKOnly
End If
Next i
End Sub

Finding Rows with same value and contracting cells

I'm trying to find all rows in a single column with the same value. The program should delete all rows that occur multiple times, apart from one of the columns, which should contract all statements from the deleted rows. This is what I have so far, but I'm getting a loop error:
Sub tester()
Sheets("Sheet1").Select
Dim one As Integer
one = 2
Dim log As Integer
log = 2
Dim compare As Integer
compare = one + 1
Dim ws As String
ws = "Sheet1"
Dim ender As String
ender = "Sheet4"
Dim counter As Integer
counter = 0
Dim lastrow As Integer
lastrow = Cells(Rows.Count, 1).End(xlUp).row
For log = 2 To lastrow - 1
one = log + counter
compare = one + 1
If Worksheets(ws).Cells(one, 1).Value = Worksheets(ws).Cells(compare,1).Value And Worksheets(ws).Cells(one, 7).Value = Worksheets(ws).Cells(compare, 7).Value Then
Do While Worksheets(ws).Cells(one, 1).Value = Worksheets(ws).Cells(compare, 1).Value And Worksheets(ws).Cells(one, 7).Value = Worksheets(ws).Cells(compare, 7).Value
If compare = one + 1 Then
Worksheets(ender).Cells(log, 1).Value = Worksheets(ws).Cells(one, 1).Value
Worksheets(ender).Cells(log, 4).Value = Worksheets(ws).Cells(one, 4).Value
Worksheets(ender).Cells(log, 2).Value = Worksheets(ws).Cells(one, 2).Value
Worksheets(ender).Cells(log, 7).Value = Worksheets(ws).Cells(one, 7).Value
End If
Worksheets(ender).Cells(log, 4).Value = Worksheets(ender).Cells(log, 4).Value & "; " & Worksheets(ws).Cells(compare, 4).Value
compare = compare + 1
counter = counter + 1
Loop
ElseIf Worksheets(ws).Cells(one, 1).Value <> Worksheets(ws).Cells(compare, 1).Value Then
Worksheets(ender).Cells(one - counter, 1).Value = Worksheets(ws).Cells(one, 1).Value
Worksheets(ender).Cells(one - counter, 2).Value = Worksheets(ws).Cells(one, 2).Value
Worksheets(ender).Cells(one - counter, 3).Value = Worksheets(ws).Cells(one, 3).Value
Worksheets(ender).Cells(one - counter, 4).Value = Worksheets(ws).Cells(one, 4).Value
Worksheets(ender).Cells(one - counter, 5).Value = Worksheets(ws).Cells(one, 5).Value
Worksheets(ender).Cells(one - counter, 7).Value = Worksheets(ws).Cells(one, 7).Value
End If
Next log
Sheets("Sheet4").Select
End Sub
Original Data
Desired output

Resources