Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #3  
Old 08-31-2017, 05:57 AM
Seiquo Seiquo is offline Delete rows with certain values (plural) Windows 7 64bit Delete rows with certain values (plural) Office 2010 64bit
Novice
Delete rows with certain values (plural)
 
Join Date: Jun 2017
Posts: 4
Seiquo is on a distinguished road
Default

Good morning Serge1p,

First thank you very much for sparing some of your time to help me. Much appreciated.

I copied your code in the Workbook1 "ThisWorkBook" code sheet as follows:

Code:
Private Function listNumbers(fileName As String, sheetName As String, columnName As String) As Long()
Dim result() As Long
Dim resultLength As Integer
Dim rangeName As String
Dim wb As Workbook
Dim rangeStartRow As Integer
Dim sh As Worksheet
Dim needToClose As Boolean
Dim i As Integer
    needToClose = True
    For i = 1 To Workbooks.Count
        If Workbooks(i).FullName = fileName Then
            needToClose = False
            Set wb = Workbooks(i)
        End If
    Next
    rangeStartRow = 2   ' change this as required
    If needToClose Then
        Set wb = Workbooks.Open(fileName, ReadOnly:=True)
    End If
    Set sh = wb.Worksheets(sheetName)
    resultLength = sh.Cells(sh.Rows.Count, columnName).End(xlUp).Row - rangeStartRow + 1
    ReDim result(resultLength - 1)
 
    For i = 1 To resultLength
        result(i - 1) = sh.Range(columnName & (rangeStartRow + i - 1)).Value
    Next
    listNumbers = result
    If needToClose Then
        wb.Close SaveChanges:=False
    End If
End Function
Public Sub DeleteRows()
Dim numbers() As Long
Dim pos As Variant
Dim cellNumber As Long
Dim cl As Range
    numbers = listNumbers("C:\Users\chevalls\Desktop\MyFile.xlsx", "Sheet1", "A")
    For Each cl In ActiveSheet.Range("A:A").Cells
        If Not IsNumeric(cl.Value) Then
            Exit For
        End If
        cellNumber = cl.Value
        pos = Application.Match(cellNumber, numbers, False)
        If Not IsError(pos) Then
        cl.Interior.ColorIndex = 1
        End If
    Next
End Sub
I changed :
- the RangeStartRow number;
- the file path, assuming that the path refers to my Workbook1; and
- added the "whatif" at the end.

When I try to run the macro, I get the error message "400"...

Do you have any idea of what I did wrong?

Thank you again.
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Get all rows based on input values from a list soolsen Excel 1 03-27-2016 08:11 PM
Delete rows with certain values (plural) Looping through rows and copy cell values to another worksheet get4hari Excel Programming 1 10-02-2015 04:51 PM
Hide rows in multiple columns based on zero values Deane Excel Programming 19 06-23-2015 11:24 PM
Delete rows with certain values (plural) Delete blank rows between the two rows that contain data beginner Excel Programming 5 12-26-2014 12:29 AM
Delete rows with certain values (plural) Delete All empty Rows - Print - Undo all Rows deleted Bathroth Word VBA 1 10-01-2014 01:40 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 03:11 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft