Updating Prices in Spreadsheet with VBA. Need help with my macro.

Marciboy

New Member
Joined
Dec 28, 2019
Messages
19
Office Version
  1. 365
Platform
  1. MacOS
In "T neu" are partially updated prices, which are assigned to serial numbers (these are not necessarily numerical). The updated prices should be inserted in the appropriate line in "T alt". The column headers are always the same in the two tables, but there are not the same number of columns (also the order is not necessarily the same in the tables). The serial numbers are uniquely assignable.
In "T neu" mostly not all serial numbers are available and sometimes there is no or the same price stored. In these two cases, the price should not be updated.
If the price is updated, it should be coloured yellow.

I've got a VBA script where I do not get any further. Maybe you could help me making it more "intelligent".

VBA Code:
Sub tt()
    On Error GoTo Fehler
    Dim TB1 As Worksheet, TB2 As Worksheet, i As Integer, j As Integer
    Dim Sp1 As Integer, Z1 As Integer, LR As Integer, LC As Integer, Spalte As Integer
    Const APPNAME = "TT"

    Application.ScreenUpdating = False
  
    Set TB1 = Sheets("T alt")
    Set TB2 = Sheets("T neu")
  
    Sp1 = 1
    Z1 = 1
     
    LC = TB2.Cells(Z1, TB2.Columns.Count).End(xlToLeft).Column
  
    For i = Sp1 To LC
        Spalte = WorksheetFunction.CountIf(TB1.Rows(Z1), TB2.Cells(Z1, i))
      
        If Spalte > 0 Then
            Spalte = WorksheetFunction.Match(TB2.Cells(Z1, i), TB1.Rows(Z1), 0)
          
            LR = TB2.Cells(TB2.Rows.Count, 1).End(xlUp).Row
          
            For j = Z1 To LR
                With TB1.Cells(j, Spalte)
                    If .Value <> TB2.Cells(j, i) Then
                        .Value = TB2.Cells(j, i)
                
                        With .Interior
                            .Pattern = xlSolid
                            .PatternColorIndex = xlAutomatic
                            .Color = 65535
                            .TintAndShade = 0
                            .PatternTintAndShade = 0
                        End With

                    End If
                End With
            Next j
        End If
      
    Next i
  
    Err.Clear
Fehler:
    Application.EnableEvents = True
    If Err.Number <> 0 Then MsgBox "Fehler in Sub """ & APPNAME & """" & vbCrLf _
        & "Fehlernummer: " & Err.Number & vbLf & Err.Description: Err.Clear
End Sub

Find my test document here: Test document
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December

Forum statistics

Threads
1,214,795
Messages
6,121,624
Members
449,041
Latest member
Postman24

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