VBA Summary in excel

Status
Not open for further replies.

Nando1988

New Member
Joined
Aug 21, 2019
Messages
23
I have a table with repeated and data I need to add up from those repeated names. I have some vba code that summarizes the data from all worksheets, but only gets the first match of the name, and I need all matches in a sheet. Can someone please help. I have the names in column B, and data I need as a summary in R and AZ.
This is the code I currently have:
Code:
Sub prueba()
Dim sh1 As Worksheet, sh2 As Worksheet, sh3 As Worksheet, sh4 As Worksheet, sh As Worksheet, c As Range, f As Range, j As Long
  
  Set sh1 = Sheets("Nombres Naranjo")
  Set sh2 = Sheets("Resumen Naranjo")
  Set sh3 = Sheets("Nombres Paraíso")
  Set sh4 = Sheets("Resumen Paraíso")
  sh2.Rows("2:" & Rows.Count).ClearContents
  
  j = 2
  For Each c In sh1.Range("A2:A800")
    For Each sh In Sheets
      Select Case sh.Name
        Case sh1.Name, sh2.Name
        Case Else
        If Not IsEmpty(sh1.Range("B2").Value) Then
            If sh.Name Like sh1.Range("B2").Value + "*El Naranjo" Then
                Set f = sh.Range("B2:B1048576").Find(c, , xlValues, xlWhole)
                If Not f Is Nothing Then
                    sh2.Cells(j, "A").Value = c
                    sh2.Cells(j, "B").Value = f.Offset(, 16)
                    sh2.Cells(j, "C").Value = f.Offset(, 50)
                    j = j + 1
                    End If
            End If
            If IsEmpty(sh1.Range("B2").Value) Then
                    sh2.Cells(j, "A").Value = c
                    sh2.Cells(j, "B").Value = f.Offset(, 16)
                    sh2.Cells(j, "C").Value = f.Offset(, 50)
                    j = j + 1
                    MsgBox "Entered else"
            End If
        End If
      End Select
    Next
  Next
    
  
End Sub
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
Status
Not open for further replies.

Forum statistics

Threads
1,224,827
Messages
6,181,194
Members
453,021
Latest member
pingpong7117

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top