VBA Loop to skip over data

bestschnauzermom

New Member
Joined
Aug 9, 2019
Messages
5
I am new to VERY new to macro building but I have reworked one that has been used where I work. I need to add a macro to the beginning of the one in use now to delete any rows that has the word "MISCELLANEOUS" in column C but NOT to delete the row if it has the word "CONCENTRATION" is in column I. I'll give an example:

Column C Column I
MISCELLANEOUS NASHVILLE, TN
MISCELLANEOUS CONCENTRATION
MISCELLANEOUS ONTARIO, CA

After this section of the macro runs I need it to continue running the current macro I have set up which starts like this:

Sub Import_From_Download()

'Make sure the download is the active document/with correct sheet.
Windows("June 17-Fees Charged.csv").Activate
Sheets("June 17-Fees Charged").Select

'Declare Variables
Dim i As Long, iLimit As Long
Dim split_text As Variant
Dim split_test(0 To 1000000) As Variant
Dim acct_st(1 To 50) As Variant
Dim acct_cr(1 To 50) As Variant
Dim acct_db(1 To 50) As Variant

'setup (assign values to) account number array
acct_st(1) = "205273"
acct_st(2) = "205275"
acct_st(3) = "205272"
acct_st(4) = "205276"
acct_st(5) = "205278"
'acct_st(5) = "205278"


Everything I have tried either gives me an error OR doesn't work at all so I'm lost. Any help is appreciated.
 

mumps

Well-known Member
Joined
Apr 11, 2012
Messages
8,528
This macro should do what you want. It assumes that you have headers in row 1 and your data starts in row 2 without any blank rows. Add your code where indicated.
Code:
Sub deleteRows()
    Application.ScreenUpdating = False
    Dim LastRow As Long
    LastRow = Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    With Cells(1).CurrentRegion
        .AutoFilter Field:=3, Criteria1:="MISCELLANEOUS"
        .AutoFilter Field:=9, Criteria1:="<>CONCENTRATION"
    End With
    With ActiveSheet
        .AutoFilter.Range.Offset(1, 0).EntireRow.Delete
        .Cells(1).AutoFilter
    End With
   [COLOR="#FF0000"] 'Your code here[/COLOR]
    Application.ScreenUpdating = True
End Sub
 

bestschnauzermom

New Member
Joined
Aug 9, 2019
Messages
5
Thank you I am excited to try it, however my spreadsheet always has blank rows. I download it from a website and I never know how many blank rows will be within the spreadsheet each day. What could skip over blank rows?
 

mumps

Well-known Member
Joined
Apr 11, 2012
Messages
8,528
Would it work for you if we deleted all the blank rows?
 

bestschnauzermom

New Member
Joined
Aug 9, 2019
Messages
5
As I read through to the end of the macro I see that it is deleting the row that has "CONCENTRATION" in it. I'm trying to preserve the row that has both MISCELLANEOUS and CONCENTRATION in it. When the file is downloaded there are multiple lines that have MISCELLANEOUS in column C but there will be different words in column I. I don't know enough about writing macros to only delete specific rows without deleting all of them.
 

mumps

Well-known Member
Joined
Apr 11, 2012
Messages
8,528
The macro below will delete all the blank rows based on the rows where column A is blank. This means that if you have some rows with data in columns other than column A with a blank cell in column A, that row will also be deleted. I can't see how your data is organized so it's hard for me to design a working macro. Also, the macro will delete the rows only if "MISCELLANEOUS " appears in column C and "CONCENTRATION" appears in column I of the same row. I think that it would be easier to help and test possible solutions if I could work with your actual file which includes any macros you are currently using. Perhaps you could upload a copy of your file to a free site such as www.box.com or www.dropbox.com. Once you do that, mark it for 'Sharing' and you will be given a link to the file that you can post here. Include a detailed explanation of what you would like to do using a few examples from your data and referring to specific cells, rows, columns and worksheets. If the workbook contains confidential information, you could replace it with generic data.

Try this macro on a copy of your file. If it doesn't work for you, I would need to see your file as I suggested above.
Code:
Sub deleteRows()
    Application.ScreenUpdating = False
    Columns("A:A").SpecialCells(xlCellTypeBlanks).EntireRow.Delete
    Dim LastRow As Long
    LastRow = Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    With Cells(1).CurrentRegion
        .AutoFilter Field:=3, Criteria1:="MISCELLANEOUS"
        .AutoFilter Field:=9, Criteria1:="<>CONCENTRATION"
    End With
    With ActiveSheet
        .AutoFilter.Range.Offset(1, 0).EntireRow.Delete
        .Cells(1).AutoFilter
    End With
    'Your code here
    Application.ScreenUpdating = True
End Sub
 

Forum statistics

Threads
1,082,290
Messages
5,364,320
Members
400,789
Latest member
Gnar

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...
Top