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.
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
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
 
Upvote 0
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?
 
Upvote 0
Would it work for you if we deleted all the blank rows?
 
Upvote 0
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.
 
Upvote 0
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
 
Upvote 0

Forum statistics

Threads
1,214,527
Messages
6,120,057
Members
448,940
Latest member
mdusw

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