0% found this document useful (0 votes)
42 views

String in Rows

This document contains a VBA macro that filters rows in Excel based on specific strings. The macro filters rows on the worksheet "Hoja1" to only show rows where column 2 contains the string "EXPANDIDO". It then counts the number of rows found and sums values from column 6 of those rows. It also checks for specific strings in column 0 and performs additional calculations if matched. The macro uses common VBA and Excel concepts like cells, ranges, filtering, loops and conditional logic.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
42 views

String in Rows

This document contains a VBA macro that filters rows in Excel based on specific strings. The macro filters rows on the worksheet "Hoja1" to only show rows where column 2 contains the string "EXPANDIDO". It then counts the number of rows found and sums values from column 6 of those rows. It also checks for specific strings in column 0 and performs additional calculations if matched. The macro uses common VBA and Excel concepts like cells, ranges, filtering, loops and conditional logic.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Houston Seminar in Excel VBA Macros

Excel Filter Rows with Cells Having


Specific Strings

Sergio Perez Rodriguez


EG, PDG, MSc

August 2020
Sub Expandiso()

Dim he, cam, rngFound, cnd, cnd1, car As String

cnd = "EXPANDIDO"

cnd1 = "Expandido"

rngFound = "BACHAQ"

Dim v, ch, ct As Integer

Dim pc, pco As Long

pc = 0

ct = 0

Set wks = Worksheets("Hoja1"): wks.Activate

cam = "Campo"

Set Match5 = wks.Cells.Find(cam)

Match5.Offset(0, 0).Select

'The onset of the autofilter looking for rows with cells containing the word "EXPANDIDO"

Cells(ActiveCell.Row, ActiveCell.Column).AutoFilter Field:=2, Criteria1:="EXPANDIDO"

With Worksheets("Hoja1").Cells

Set Match1 = wks.Cells.Find(rngFound)

Match1.Offset(0, 0).Select

Range(Selection, Selection.End(xlDown)).Select

Set he = Selection

ch = he.Rows.Count

MsgBox "Total # of fields " & ch


End With

For v = 1 To ch

dnc = Match1.Offset(v, 1).Value

'MsgBox dnc

Select Case dnc

Case cnd, cnd1

'MsgBox Match1.Offset(v, 6).Value

pc = pc + Match1.Offset(v, 6).Value

ct = ct + 1

car = Match1.Offset(v, 0).Value

Select Case car

Case Is = "CARDON"

Range("K2") = Round(Match1.Offset(v, 6).Value, 0)

Case Else

'Do nothing

End Select

Case Else

'do nothing

End Select

Next v

End Sub
Bibliography

Jelen, B., Syrstad, T. 2016. Excel 2016 VBA and Macros. Pearson Education.

Roman, S. 2002. Writing Excel Macros with VBA. O’Reilly

Alexander, M. & Walkenbach, J. 2018. Excel VBA Programming For Dummies. Wiley

You might also like