help on modifying a macro

congokin

Board Regular
Joined
Oct 31, 2010
Messages
74
i am working with the following sheet and need some help
Excel Workbook
AB
1HELP!!!!!!Urgenthttp://www.mrexcel.com/forum/showthread.php?t=4994
2Vlookup, not worrking as described.http://www.mrexcel.com/forum/showthread.php?t=4995
3HELP Urgent (sugar1525)http://www.mrexcel.com/forum/showthread.php?t=4996
4Vlookup, not working as described.http://www.mrexcel.com/forum/showthread.php?t=4997
5Remove data from a text string in a single cell and place inhttp://www.mrexcel.com/forum/showthread.php?t=4804
6COMBO BOX Drop List Functionhttp://www.mrexcel.com/forum/showthread.php?t=4933
Sheet1
Excel 2007

and i got the following code from mr excel podcast
http://www.youtube.com/watch?v=K9V5E_LPiKs<code>
Sub LoopThrough()
' this macro is taken from
' http://www.youtube.com/watch?v=K9V5E_LPiKs
Dim wso As Worksheet
Set wso = ActiveSheet

For Each Cell In wso.Range("B1:B5")
ActiveWorkbook.Worksheets.Add
ThisURL = "URL;" & Cell.Value

With ActiveSheet.QueryTables.Add(Connection:= _
ThisURL, Destination:=Range("$B$1"))
.Name = "f-10"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.WebSelectionType = xlEntirePage
.WebFormatting = xlWebFormattingNone
'xlWebFormattingAll All formatting is imported.
'xlWebFormattingNone No formatting is imported.
'xlWebFormattingRTF Rich Text Format compatible formatting is imported.
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.WebDisableRedirections = False
.Refresh BackgroundQuery:=True
End With
Next Cell

End Sub</code>

what i need is to modify the above macro to display info on all the urls (colA) on a single master sheet instead of opening 5 worksheets as per the above code
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Just a suggestion, since I haven't tried it on test data.
Rich (BB code):
Sub LoopThrough()
' this macro is taken from
' http://www.youtube.com/watch?v=K9V5E_LPiKs
Dim wso As Worksheet, x as integer
Set wso = ActiveSheet

ActiveWorkbook.Worksheets.Add.Name = "mastersheet"
For Each Cell In wso.Range("B1:B5")
x = x + 1
ThisURL = "URL;" & Cell.Value

With Sheets("mastersheet").QueryTables.Add(Connection:= _
    ThisURL, Destination:=Range("$B$1").Offset(, 4 * x - 4))
.Name = "f-10"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.WebSelectionType = xlEntirePage
.WebFormatting = xlWebFormattingNone
'xlWebFormattingAll All formatting is imported.
'xlWebFormattingNone No formatting is imported.
'xlWebFormattingRTF Rich Text Format compatible formatting is imported.
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.WebDisableRedirections = False
.Refresh BackgroundQuery:=True
End With
Next Cell

End Sub
Although trying to sort out code written by others is usually a pretty thankless task.
 
Upvote 0
I tried it again and the macro WORKS. thanks...
But i was wondering if the webpage info could show up in rows instead of colums...
 
Upvote 0
to be more clear...the macro above works great but the info are shown columns by columns (ie colB to colF) has info on url1, then colG to colK has info on url2 and so on...
what i would like to see is having info of url1 from a1 to a20(as an example), and info of url2 from a21 to a31 (as an example) and so on
url2 should start on the last row of info from url1. i hope this helps
 
Upvote 0
Hey,

I don't know that anything I suggest would work, coz I don't have test data to check it against.

And, as noted, trying to sort out code written by others is never much fun.

However as a suggestion for producing transposed results, you might like to try modifying the code as indicated:
Rich (BB code):
Sub LoopThrough()
' this macro is taken from
' http://www.youtube.com/watch?v=K9V5E_LPiKs
Dim wso As Worksheet, x as integer
Set wso = ActiveSheet

ActiveWorkbook.Worksheets.Add.Name = "mastersheet"
For Each Cell In wso.Range("B1:B5")
x = x + 1
ThisURL = "URL;" & Cell.Value

With Sheets("mastersheet").QueryTables.Add(Connection:= _
    ThisURL, Destination:=Range("$B$1").Offset(, 4 * x - 4))
'May need to modify the Offset(...) in above line to allow for transposition. Try experimenting with this to suit you.
'anything before the comma is row offset (here it's blank, i.e default=unchanged)
'after the comma is column offset
'maybe, if it otherwise transposes ok, just remove the comma to get row offset as you want it
'you can safely delete these green lines whenever you like
.Transpose = true
.Name = "f-10"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.WebSelectionType = xlEntirePage
.WebFormatting = xlWebFormattingNone
'xlWebFormattingAll All formatting is imported.
'xlWebFormattingNone No formatting is imported.
'xlWebFormattingRTF Rich Text Format compatible formatting is imported.
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.WebDisableRedirections = False
.Refresh BackgroundQuery:=True
End With
Next Cell

End Sub
 
Upvote 0
getting a run time error '438'. tried to play with the offset option but could not get it to work...
 
Upvote 0
OK.

So let me suggest the following.

1. Use the code I posted in post #3 with the following modification
Rich (BB code):
With Sheets("mastersheet").QueryTables.Add(Connection:= _
    ThisURL, Destination:=Range("$B$1").Offset(, 7 * x - 7))
(that is, use 7 instead of 4). But don't use the transposition inclusion that I suggested.

2. Wait until the queries have finished downloading; they should all be there with a single column between each table.

3. I understand you next want these tables transposed, instead of keeping them as they are.

4. Rather than writing more code myself, could you then look at the Microsoft link http://support.microsoft.com/kb/182822 and follow the steps there.

5. This should give you the transposed result you want. If all looks OK and you then want to code it with some VBA code, try following the Microsoft steps while using the macro recorder and see how you get on.

6. Good luck!
 
Upvote 0

Forum statistics

Threads
1,224,598
Messages
6,179,818
Members
452,946
Latest member
JoseDavid

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