a VBA beginner starter demonstration to paste to the (OUT_PUT_DATA) worksheet module :
PHP Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim K, H, L, N&, V, R&, C%
If Target.Address <> "$B$1" Then Exit Sub
Application.EnableEvents = False
Me.UsedRange.Offset(1).Clear
If IsEmpty(Target) Then Application.EnableEvents = True: Exit Sub
K = [{2,3,4,15}]
H = Application.Index(Worksheets(1).UsedRange.Rows(1), , K)
L = Application.Index(Worksheets(1).UsedRange.Rows(1), , [{16,16,17,17}])
For N = 1 To Me.Index - 1
With Sheets(N).UsedRange
V = Application.Match(Target, .Columns(1), 0)
If IsNumeric(V) Then
Cells(R + 2, 1).Value2 = .Parent.Name
Cells(R + 3, 1).Resize(, UBound(K)).Value2 = H
R = R + 4
Cells(R, 1).Resize(, UBound(K)).Value2 = Application.Index(.Rows(V), , K)
For C = 5 To 13 Step 2
If IsEmpty(.Cells(V, C)) Then Exit For
R = R + 1
Cells(R, 2).Resize(, 2).Value = .Cells(V, C).Resize(, 2).Value
Next
R = R + 1
L(2) = .Cells(V, 16).Value2: L(4) = .Cells(V, 17).Value2
Cells(R, 1).Resize(, UBound(L)).Value2 = L
End If
End With
Next
Application.EnableEvents = True
End Sub
Do you like it ? So thanks to click on bottom left star icon « ★ Add Reputation » !
Last edited by Marc L; 01-19-2020 at 04:01 PM.
Reason: oups …
This part of the code is what I don't understand, I want you to explain them to me. Thanks again.
V = Application.Match(Target, .Columns(1), 0)
If IsNumeric(V) Then
Cells(R + 2, 1).Value2 = .Parent.Name
Cells(R + 3, 1).Resize(, UBound(K)).Value2 = H
R = R + 4
Cells(R, 1).Resize(, UBound(K)).Value2 = Application.Index(.Rows(V), , K)
For C = 5 To 13 Step 2
If IsEmpty(.Cells(V, C)) Then Exit For
R = R + 1
Cells(R, 2).Resize(, 2).Value = .Cells(V, C).Resize(, 2).Value
Next
R = R + 1
L(2) = .Cells(V, 16).Value2: L(4) = .Cells(V, 17).Value2
Cells(R, 1).Resize(, UBound(L)).Value2 = L
a VBA beginner starter demonstration to paste to the (OUT_PUT_DATA) worksheet module :
PHP Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim K, H, L, N&, V, R&, C%
If Target.Address <> "$B$1" Then Exit Sub
Application.EnableEvents = False
Me.UsedRange.Offset(1).Clear
If IsEmpty(Target) Then Application.EnableEvents = True: Exit Sub
K = [{2,3,4,15}]
H = Application.Index(Worksheets(1).UsedRange.Rows(1), , K)
L = Application.Index(Worksheets(1).UsedRange.Rows(1), , [{16,16,17,17}])
For N = 1 To Me.Index - 1
With Sheets(N).UsedRange
V = Application.Match(Target, .Columns(1), 0)
If IsNumeric(V) Then
Cells(R + 2, 1).Value2 = .Parent.Name
Cells(R + 3, 1).Resize(, UBound(K)).Value2 = H
R = R + 4
Cells(R, 1).Resize(, UBound(K)).Value2 = Application.Index(.Rows(V), , K)
For C = 5 To 13 Step 2
If IsEmpty(.Cells(V, C)) Then Exit For
R = R + 1
Cells(R, 2).Resize(, 2).Value = .Cells(V, C).Resize(, 2).Value
Next
R = R + 1
L(2) = .Cells(V, 16).Value2: L(4) = .Cells(V, 17).Value2
Cells(R, 1).Resize(, UBound(L)).Value2 = L
End If
End With
Next
Application.EnableEvents = True
End Sub
Do you like it ? So thanks to click on bottom left star icon « ★ Add Reputation » !
The mention tag failed , so I have to use this method
Can you please adjust the previous code to suit for me?
I won't waste time if you at least well follow the direction in my previous post
and my demonstration still does not work on your side with your original attachment !
As another point I work only on what I can load under Excel …
Re: Fill a sheet with data from three different sheets, same workbook, in a very tricky wa
Originally Posted by Marc L
I won't waste time if you at least well follow the direction in my previous post
and my demonstration still does not work on your side with your original attachment !
As another point I work only on what I can load under Excel …
Okay thanks.
But I will be glad if you can add some comments to the part of code I posted in post #6
Except Application.Match which is the MATCH worksheet function (so to see first in the Excel inner help if necessary)
all statements are yet in the VBA inner help : just place the text cursor on a statement, hit F1 key then read …
As that's the way I learned VBA.
Another tip to understand what each codeline does : add first a breakpoint (F9 key) in the worksheet module at the beginning of the event, on sheet side change the B1 cell value,
the execution stops on the breakpoint codeline then you can watch out what happens on sheet side
or for any variable see its value within the VBE Locals window. Move to the next codeline via hitting F8 key (step-by-step mode) …
Bookmarks