Changing value of cell in first row of filtered data

THuebbe

New Member
Joined
Jan 3, 2021
Messages
1
Office Version
  1. 2010
Platform
  1. Windows
Hello,

I have a rather large spreadsheet named "Master" ( about 244k rows) of pricing information for a customer. Each row has a part number, brand name, pricing category, cost, margin, and price column. As it goes, it's time for annual price increases from vendors and I'm trying automate the update. I have a second sheet named "Sheet1" that has just the values that need updating. Basically this is supposed to go line by line on Sheet1, filter that part number on Master, then change the price cell value. It all works just fine as long as there are no duplicates. Unfortunately there are duplicates. I'm hoping you fine folk can help me figure out how to only worry about the first line. The error is happening on the line " comparePart = Sheets("Master").Range("B2:B" & LR).SpecialCells(xlCellTypeVisible) ", and only because, I assume, it's trying to grab a string value to compare but is getting multiple issues. Any suggestion? Thank you!!

VBA Code:
Sub UpdateCosts()

'Application.ScreenUpdating = False

ClearImportTableFilters

Dim comparePart As String
Dim importPart As String
Dim i As Long

Dim LR As Long
LR = Sheets("Master").Range("A" & Rows.Count).End(xlUp).Row

    For i = 2 To Sheets("Sheet1").Rows.Count

        importPart = Sheets("Sheet1").Cells(i, 2)
        
        Sheets("Master").Range("TableParts[Item Id]").AutoFilter Field:=2, Criteria1 _
        :=importPart
        
        comparePart = Sheets("Master").Range("B2:B" & LR).SpecialCells(xlCellTypeVisible)
        
    
        If comparePart = importPart Then
            Sheets("Master").AutoFilter.Range.Offset(1).SpecialCells(xlCellTypeVisible).Cells(1, 2).Select
        End If
                
                
        ClearMasterTableFilters

        Sheets("Margins").Range("H9") = i

        
    Next i

'Application.ScreenUpdating = True

End Sub
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
This code just avoid the error what you said but I don't think it will meet your needs. If you show some pictures about Sheet1 and Master sheet at least hedders, you might get other answers.
And this code
"For i = 2 To Sheets("Sheet1").Rows.Count"
You will loop one million times. It might be like " Sheets("Sheet1").Range("A" & Rows.Count).End(xlUp).Row".
Hope this helps.

VBA Code:
Sub UpdateCosts()

'Application.ScreenUpdating = False

'ClearImportTableFilters

Dim comparePart As String
Dim importPart As String
Dim i As Long

Dim LR As Long
    With Sheets("Master")
        LR = .Range("A" & Rows.Count).End(xlUp).Row

        For i = 2 To Sheets("Sheet1").Rows.Count

            importPart = Sheets("Sheet1").Cells(i, 2)
        
            .Range("TableParts[Item Id]").AutoFilter Field:=2, Criteria1:=importPart
            If WorksheetFunction.Subtotal(3, .Range("A:A")) = 2 Then
                comparePart = .Cells(Rows.Count, 2).End(xlUp).Value
                If comparePart = importPart Then
                    Sheets("Master").AutoFilter.Range.Offset(1).SpecialCells(xlCellTypeVisible).Cells(1, 2).Select
                End If
            Else
            
            End If
                
        'ClearMasterTableFilters

            Sheets("Margins").Range("H9") = i
        Next i
    End With
'Application.ScreenUpdating = True

End Sub
 
Upvote 0

Forum statistics

Threads
1,213,563
Messages
6,114,332
Members
448,566
Latest member
Nickdozaj

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