Query
Almir...
Please find the appended revised Query sheet.
The cells next to the 1st appearance of those 10 tiffs have to be filled with the 1st Element (Borrower) from sheet-3.
Cells next to the 2nd appearance of those 10 tiffs have to be filled with the 2nd Element (Lender) from sheet-3 and so on.
Manny's VBA script works but is there any way without getting into VBA script?
Please advise.
My curious quest to learn VBA scripting is still left unanswered. Could you please share your ideas.
Thanks & Regards
Kumar.
Attachment | Size |
---|---|
Query111312.xlsx | 10.92 KB |
RE: Query
Hi,
Here's some smart VBA way:
' ************************* ' ************************* '
Sub MyQuery()
Dim oQueryWsh As Worksheet
Dim oDocWsh As Worksheet
Dim oElemWsh As Worksheet
Dim oQueryRng As Range
Dim oDocRng As Range
Dim oElemRng As Range
Dim lngDocNum As Long
Dim lngElemNum As Long
Dim oDestRng As Range
Dim i As Long
Dim j As Long
Application.ScreenUpdating = False
Set oQueryWsh = Sheet1
Set oDocWsh = Sheet2
Set oElemWsh = Sheet3
With oQueryWsh.UsedRange
Set oQueryRng = _
.Offset(1, 0).Resize(.Rows.Count - 1, .Columns.Count)
oQueryRng.Clear
End With
With oDocWsh.UsedRange
Set oDocRng = _
.Offset(1, 0).Resize(.Rows.Count - 1, 1)
End With
With oElemWsh.UsedRange
Set oElemRng = _
.Offset(1, 0).Resize(.Rows.Count - 1, 1)
End With
lngDocNum = oDocRng.Rows.Count
lngElemNum = oElemRng.Rows.Count
Set oDestRng = _
oQueryRng.Cells(1, 2).Resize(lngDocNum * lngElemNum, 1)
oDocRng.Copy oDestRng
With oQueryRng.Cells(1, 1)
.Value = 1
.AutoFill _
Destination:=.Resize(lngDocNum * lngElemNum, 1), _
Type:=xlFillSeries
End With
i = 1
For j = 1 To lngElemNum
oQueryRng.Cells(i, 3).Value = oElemRng.Cells(j, 1).Value
i = i + lngDocNum
Next j
Set oDestRng = Nothing
Set oElemRng = Nothing
Set oDocRng = Nothing
Set oQueryRng = Nothing
Set oElemWsh = Nothing
Set oDocWsh = Nothing
Set oQueryWsh = Nothing
Application.ScreenUpdating = True
End Sub
' ************************* ' ************************* '
Best regards.
Pasting copied data for several times at once
Manny...
Thank you so much for providing 66 line of code in VBA but this is what I am afraid of as I know nothing about VBA Script.
I have expected a solution in pure Excel.
Since the time I have been a member of this group, observed many coming with questions related to VBA Scripting. Probably they are finding smart solutions through VBA Script.
So, I think it is the time for me to take further step and learn VBA Scripting. I cannot sit behind.
Please let me know how do I start with VBA Scripting.
Regards
Kumar.
Pasting copied data for several times at once
CTRL+C, Select 10 non-contiguous cells in 10 ranges (only the first cell in each range), CTRL+V.
Almir... Thank you for the
Almir...
Thank you for the inputs but this may not work for the way I wanted the data to be in the sheet.
I will be editing my initial posting to add the revised sheet. Please review that sheet and suggest.
Regards
Kumar.
Almir... Thank you for the
In C2 (Element) paste this formula:
=INDEX(Sheet3!$A$1:$A$11;COUNTIF($B$2:B2;"1234_0456.0789.tif")+1).
It checks in column A how many times 1234....tif occurs. It takes number of occurences and add 1 (due to row with headers) and return Element with that ordinal number from sheet 3. When it counts 123...tif two times, it changes Element to the second element, and so on.
This assumes that you always have the same order of .tifs.
Hope this helps.
Thanks a lot Almir. The above
Thanks a lot Almir.
The above combination of functions -INDEX & COUNTIF has helped a lot.
Regards
Kumar.