A little detail in my code

Status
Not open for further replies.

hpernaf

New Member
Joined
Jul 1, 2019
Messages
27
Hi everyone.
I recently got help here on the forum to get a VBA code that adds products with autofilter through a form with LisBox.

However, in the original code, items start to be added from cell A2.
I would like to start getting records from cell A14.

This seems a little simple, but as the code contains filters, I always end up misconfiguring the script that registers the cells and columns correctly.

Below is my code and attached is my spreadsheet.
Where should I change so that the records are inserted from cell A14?

VBA Code:
Private Sub btn_inserirpartida_Click()
Application.ScreenUpdating = False
    Dim Rng As Range, RngList As Object, WS1 As Worksheet, WS2 As Worksheet, desWS As Worksheet, key As Variant, n, i As Integer
    Dim ultimalinha As Long, fVisRow As Long, lVisRow As Long, ID As Range, totE As Double, totH As Double, rowCount As Long, x As Long
    Set ws = ThisWorkbook.Sheets("Pedido")
    ws.Activate
    

    n = ws.Range("A1").CurrentRegion.Rows.Count + 1
    
    i = ListBoxProdutos3.ListCount - 1
    Range(ws.Cells(n, 1), Cells(n + i, 8)).Value = ListBoxProdutos3.List
    ultimalinha = Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    Set RngList = CreateObject("Scripting.Dictionary")
    For Each Rng In Range("B2", Range("B" & Rows.Count).End(xlUp))
        If Not RngList.Exists(Rng.Value) Then
            RngList.Add Rng.Value, Nothing
        End If
    Next
    For Each key In RngList
        With ActiveSheet
            .Cells(1, 2).CurrentRegion.AutoFilter 2, key
            rowCount = .[subtotal(103,B:B)] - 1
            If rowCount > 1 Then
                fVisRow = .Range("A2:A" & ultimalinha).SpecialCells(xlCellTypeVisible).Cells(1, 2).Row
                lVisRow = .Cells(Rows.Count, "A").End(xlUp).Row
                
                For Each Rng In .Range("D" & fVisRow & ":D" & lVisRow).SpecialCells(xlCellTypeVisible)
                    totE = totE + Rng
                    totH = totH + Rng.Offset(, 2)
                Next Rng
                .Range("D" & fVisRow) = totE
                .Range("G" & fVisRow) = totH
                For x = ultimalinha To fVisRow + 1 Step -1
                    If .Rows(x).Hidden = False Then .Rows(x).Delete
                Next x
            End If
        End With
        totE = 0
        totH = 0
    Next key
    Range("B1").AutoFilter
    Unload Me
    Application.ScreenUpdating = True
    MsgBox "Sale successfully registered!"


 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
Status
Not open for further replies.

Forum statistics

Threads
1,215,046
Messages
6,122,852
Members
449,096
Latest member
Erald

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