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,506
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,506
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,506
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,081,691
Messages
5,360,637
Members
400,591
Latest member
badgergurl

Some videos you may like

This Week's Hot Topics

  • VBA (Userform)
    Hi All, I just would like to know why my code isn't working. Here is my VBA code: [CODE=vba]Private Sub OKButton_Click() Dim i As Integer...
  • List box that changes fill color
    Hello, I have gone through so many pages trying to figure this out. I have a 2020 calendar that depending on the day needs to have a certain...
  • Remove duplicates and retain one. Cross-linked cases
    Hi all I ran out of google keywords to use and still couldn't find a reference how to achieve the results of a single count. It would be great if...
  • VBA Copy and Paste With Duplicates
    Hello All, I'm in need of some input. My VBA skills are sub-par at best. I've assembled this code from basic research and it works but is...
  • Macro
    is it possible for a macro to run if the active cell value is different to the value above it
  • IF DATE and TIME
    I currently use this to check if date has passed but i also need to set a time on it too. Is it possible? [CODE=vba]=IF(B:B>TODAY(),"Not...
Top