Web query messing up existing formatting despite being told not to...

bluto32

New Member
Joined
Jan 5, 2011
Messages
37
I am writing a macro to fetch some "frequency & symbol rates" data from a website.

The data typically looks like this: 22000 5/6

When the query is performed, although the data looks fine on the screen, it has been converted into a fraction. Clicking on the cell reveals it's true nature: 22000.833333333333...

This is a problem, as I would like to read off the last 3 characters as a string "5/6" and use them somewhere else.

My code is below, and was generated with the macro recorder. I have tried formatting the entire worksheet as "Text" before running the code, but this doesn't help. Clicking cell I36 shows it has been changed from "Text" format to "Fraction" format. Oddly enough, the whole numbers in other cells are still formatted as text! Is this a bug?

Code:
Sub Webpage()
With ActiveSheet.QueryTables.Add(Connection:= _
"URL;http://en.kingofsat.net/pos-28.2E.php", Destination:=Range("A1"))
.Name = "Web query"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
[COLOR=seagreen].PreserveFormatting = True               [/COLOR][COLOR=magenta]'Oh no it isn't...[/COLOR]
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = False
.RefreshPeriod = 0
.WebSelectionType = xlEntirePage
.WebFormatting = xlWebFormattingNone
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = True
.WebDisableRedirections = False
.Refresh BackgroundQuery:=False
End With
End Sub

Bluto
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
I don't do web queries, but just ran your code on a virgin worksheet, and cell I36 contains 2200 5/6 as text.

Re-ran the code, same thing.
 
Last edited:
Upvote 0
Thanks for this.

I've just done the same here, also on a brand new workbook, but still get it formatted as a fraction. :(

I'm using Excel 2010 on Windows 7 Ultimate, fully up to date (as far as I know - my machine gets important/critical updates for Windows and Office automatically).

Bluto
 
Upvote 0
I used 2003/2007 on XP.

Assuming your cells are formatted as General when you started (as mine were), I don't have another suggestion, sorry.
 
Upvote 0
Don't know how to address the underlying issue, but you could throw this in at the end of your procedure...

Code:
Range("I36").Value = "'" & Range("I36").Text
 
Upvote 0
shg - Thanks for getting back to me about your versions of Excel; I guess this is a bug in Excel 2010.

Gregtx - Thank you for your suggestion!!!

I'm relatively new to VBA and haven't used ".Text" before; it makes the underlying issue straightforward to deal with. I have now captured those last three characters ("5/6") with:

Code:
Dim mystring As String
mystring = Right(Range("I36").Text, 3)

mystring now contains "5/6" rather than the "333" from before.

Many thanks indeed - project up and running again :)

Bluto
 
Upvote 0

Forum statistics

Threads
1,224,522
Messages
6,179,299
Members
452,904
Latest member
CodeMasterX

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