Need to restructure data received from web into excel
Tag : excel , By : Brianna
Date : March 29 2020, 07:55 AM
around this issue I have a excel macro that searches many values in a column and puts the data into another worksheet. However the data is scattered and need to arrange it. , To answer your latest updated question Sub Search2()
Dim i As Integer, n As Integer, SearchString As String
Dim shFinal As Worksheet, shQuery As Worksheet, shAllData As Worksheet
Dim iRet As Integer
Dim strPrompt As String
Dim strTitle As String
Dim m As Long, p As Long, q As Long, r As Long, s As Long
Dim range As range
Dim vSrc As Variant, vDest() As Variant
Dim r1 As range
strPrompt = "Hit OK when you wish to proceed to the next search item."
strTitle = "Next Search"
Set shFinal = Sheets("FINAL")
Set shQuery = Sheets("Query")
Set shAllData = Sheets("AllData")
n = shFinal.range("C2").End(xlDown).Row
q = 1
For i = 2 To n
SearchString = shFinal.Cells(i, 3).Value
Set qt = shQuery.QueryTables.Add(Connection:= _
"URL;https://www.***.com/catalog/***.hsm?ItemNumber=" & SearchString _
, Destination:=Worksheets("Query").range("A1"))
With qt
.Name = SearchString
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = False
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlOverwriteCells
.SavePassword = True
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.WebSelectionType = xlSpecifiedTables
.WebTables = "1"
.WebFormatting = xlWebFormattingNone
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.WebDisableRedirections = False
On Error Resume Next '<-- Added line
.Refresh BackgroundQuery:=False
End With
If Err = 0 Then '<-- Added line
On Error Goto 0 '<-- Added line
shAllData.Cells(q, 1) = SearchString
p = 1
Do While p < 30
If shQuery.Cells(p, 4) Like "Replaces:*" Then shAllData.Cells(q, p) = shQuery.Cells(p, 5)
If shQuery.Cells(p, 4) Like "Crossed From:*" Then shAllData.Cells(q, p) = shQuery.Cells(p, 5)
If shQuery.Cells(p, 4) Like "Crosses To:*" Then shAllData.Cells(q, p) = shQuery.Cells(p, 5)
Set range = shQuery.range("E2:E25")
For Each cell In range
If IsEmpty(cell) Then
Exit For
Else
r = p + 1
shAllData.Cells(q, r) = shQuery.Cells(r, 5)
End If
Next
p = p + 1
Loop
iRet = MsgBox(strPrompt, vbYesNo, strTitle)
If iRet = vbNo Then
shQuery.UsedRange.ClearContents
End
Else
shQuery.UsedRange.ClearContents
End If
q = q + 1
End If '<-- Added line
Err = 0 '<-- Added line
Next i
End Sub
|
How to split and restructure cells using excel VBA
Tag : excel , By : platformNomad
Date : March 29 2020, 07:55 AM
To fix the issue you can do call ResizeToFit macro at the end of your code Add ResizeToFit right before End Sub in your current code ...
Next lRow
ResizeToFit ' or Call ResizeToFit
End Sub
...
Sub ResizeToFit()
Application.ScreenUpdating = False
Dim i As Long
For i = Range("D" & Rows.Count).End(xlUp).Row To 1 Step -1
If IsEmpty(Range("D" & i)) Then
Rows(i & ":" & i).Delete
Else
Range("E" & i) = Split(Range("D" & i), Chr(32))(1)
Range("D" & i) = Split(Range("D" & i), Chr(32))(0)
End If
Next i
For i = 1 To 5
If i <> 4 Then
Cells(1, i).Resize(Range("D" & Rows.Count).End(xlUp).Row, 1).Value = Cells(1, i)
End If
Next
Application.ScreenUpdating = True
End Sub
|
Restructure XML in PHP
Date : March 29 2020, 07:55 AM
will help you Okay, I think the key problem here is that assigning the images to $images doesn't work like you'd expect. While such an assignment of a primitive makes a copy, assigning an object makes a reference to the same object (similar to a pointer you've worked with lower level languages). They do this because an object can be larger than a primitive, and unnecessary duplication of that is just wasteful. However, in this case, the result is that when you unset the images from the main SimpleXML object, you're also destroying the instance in $images. Fortunately, there is a solution. You can clone the object, rather than assigning it. See http://www.php.net/manual/en/language.oop5.cloning.php<?php
//$xml = simplexml_load_file('data.xml');
$xml = simplexml_load_string('<items>
<item>
<images>
<image>A</image>
<image>B</image>
<image>C</image>
</images>
</item>
</items>');
// Loop over items in original xml
foreach ($xml->item as $item) {
if (count($item->images->image) > 1) {
// Clone entry
$images = clone $item->images;
// Remove entry and replace with empty
unset($item->images);
$item->addChild('images');
for ($i = 0; $i < count($images->image); $i++) {
$num = ($i > 0) ? $i : '';
$item->images->addChild('image'.$num, $images->image[$i]);
}
}
}
//$xml->asXML('POTO.xml');
echo $xml->asXML();
|
How can I restructure a JS object?
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , I have a list of appointments structured like so (taken from JSON format): , You can use reduce - var newData = oData.data.d.results.reduce(function(prev,curr){
if (!prev[curr.Room]) { // if room not already in the object add it.
prev[curr.Room] = [];
}
prev[curr.Room].push(curr);
return prev;
}, {}); // init with an empty object
console.log(newData);
|
Restructure column to row in Excel
Date : March 29 2020, 07:55 AM
it helps some times As far as I understand you want the following: Column M as the header. A B C D
1 Benzen EthyBenzen m*p-Xxen
2 835-2017-5623
3 835-2017-5624
4 835-2017-5625
=ISERROR(VLOOKUP($A2,IF($M$1:$M$10000=B$1,$B$1:$N$10000,""),13,FALSE),"")
A B C D
1 Benzen EthyBenzen m*p-Xxen
2 835-2017-5623 >0,1
3 835-2017-5624 >0,1
4 835-2017-5625 >0,1
|