Difficult but not impossible

decent_boy

Board Regular
Joined
Dec 5, 2014
Messages
130
Office Version
  1. 2016
Platform
  1. Windows
Hello, hope that you are well

I need a macro for my result sheet , let me explain you that i have sheet1 and there are 3 fields from col a to c and i need a macro for result sheet which matches ID number from result sheet col a (where DI# is blank in col b) with sheet1 col a and copy/distribute b col value from sheet1 to result sheet in col c which must be equal d col value , ok please see below example in red highlighted font cells as a macro result.

Sheet1
IDEDI #Qty
A11A12452
A11A13451
A11A154510
A16B45673
A16B678930

<colgroup><col width="64" span="3" style="width:48pt"> </colgroup><tbody>
</tbody>

Result Sheet
IDDI#EDI #Qty
A11-A12452
A11-A13451
A11-A15451
A122345 1
A133245 1
A16-B45673
A16-B67892
A16-B67891

<colgroup><col><col><col><col></colgroup><tbody>
</tbody>
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
Rick , below solution has been provided on previous post link


Code:
Sub Data_base()
Dim ws1 As Worksheet, ws2 As Worksheet, ws3 As Worksheet
Dim rng2 As Range
Dim LRws1 As Long, LRws3 As Long
Dim chk As Variant
Dim match_formula As Variant


Set ws1 = Sheets("Fruit Data Base")
Set ws2 = Sheets("Fruit Order List")


Application.ScreenUpdating = False


ws1.Copy After:=Worksheets(Worksheets.Count)
Worksheets(Worksheets.Count).Name = "Helper_sheet"
     
Set ws3 = Sheets("Helper_sheet")


On Error Resume Next
LRws2 = ws2.UsedRange.Rows.Count
LRws3 = ws3.UsedRange.Rows.Count


Set rng2 = ws2.Range("D3:D" & LRws2)




For Each r In rng2
    If r.Offset(, -1).Value = 0 Or r.Offset(, -1).Value = "-" Then
        r.Value = "!"
        For i = 1 To LRws3
            If ws3.Range("A1").Offset(i).Value = r.Offset(, -2).Value And ws3.Range("A1").Offset(i, 3).Value = r.Offset(, 1).Value Then
            r.Value = ws3.Range("A1").Offset(i, 2).Value
            ws3.Range("A1").Offset(i, 2).EntireRow.Delete
            GoTo Skip1
            End If
        Next i
      End If
Skip1:
Next r


LRws3 = ws3.UsedRange.Rows.Count


For Each r In rng2
    If r.Value = "!" Then
        For i = 1 To LRws3
            If ws3.Range("A1").Offset(i).Value = r.Offset(, -2).Value And ws3.Range("A1").Offset(i, 3).Value > r.Offset(, 1).Value Then
            ws3.Range("A1").Offset(i, 4).Value = ws3.Range("A1").Offset(i, 3).Value - r.Offset(, 1).Value
            End If
        Next i
     
        For i = 1 To LRws3
            If WorksheetFunction.Max(ws3.Range("A1:A" & LRws3).Offset(, 4)) > 0 And ws3.Range("A1").Offset(i, 4).Value = WorksheetFunction.Min(ws3.Range("A1:A" & LRws3).Offset(, 4)) Then
                r.Value = ws3.Range("A1").Offset(i, 2).Value
                ws3.Range("A1").Offset(i, 3).Value = ws3.Range("A1").Offset(i, 4).Value
                ws3.Range("A1:A" & LRws3).Offset(, 4).ClearContents
                GoTo skip2
            End If
        Next i
    End If
skip2:
    
Next r


Application.DisplayAlerts = False
ws3.Delete


Application.DisplayAlerts = True
Application.ScreenUpdating = True


End Sub
 
Upvote 0

Forum statistics

Threads
1,216,041
Messages
6,128,467
Members
449,455
Latest member
jesski

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