?
Solved

Run Macro

Posted on 2011-02-19
3
Medium Priority
?
277 Views
Last Modified: 2012-05-11
Hello trying to figure this out i have a macro see below.  I need to run the macro until strData does not have a value.  but also need a way to change the cell location of strData each time run, for example the first run strData will be the value at 55,2, the next run is 56,2, the next 57,2 until the last data in that column, then end macro.

Dim strURL, strURL1, strURL2, strURL3, strData
    On Error Resume Next
    'called from Sheet1 where A12 contains - pafb
   
    strData = Sheets("Control").Cells(55, 2)
   
    'change sheets
    Sheets("Sheet1").Activate   'sheet named WebData to hold returned data
   
    'clear last web query
    'Cells.Select
    'Selection.Clear
    'this line will fail if there isn't an existing web query - comment out the first time around...
    'Selection.QueryTable.Delete

    'return to top
    'Cells(1, 1).Select
   
    'get new web data
    strURL = "URL;http://68.226.77.253/text/NAMSFC/NAM_" & strData & ".txt"
    strURL1 = "URL;http://charlie.wxcaster.com/text/GFSSFC/GFS_" & strData & ".txt"
    strURL2 = "URL;http://www.nws.noaa.gov/cgi-bin/lamp/getlav.pl?sta=" & strData
    strURL3 = "URL;http://weather.uwyo.edu/cgi-bin/wyowx.fcgi?TYPE=metar&DATE=current&HOUR=current&UNITS=A&STATION=" & strData
    Range("A1").Select
    With Selection.QueryTable
        .Connection = strURL
        .WebSelectionType = xlAllTables
        .WebFormatting = xlWebFormattingNone
        .WebPreFormattedTextToColumns = False
        .WebConsecutiveDelimitersAsOne = True
        .WebSingleBlockTextImport = False
        .WebDisableDateRecognition = False
        .WebDisableRedirections = False
        .Refresh BackgroundQuery:=False
    End With
0
Comment
Question by:sandramac
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 30

Accepted Solution

by:
SiddharthRout earned 2000 total points
ID: 34934236
Is this what you are trying?

Sub Sample()
    Dim strURL As String, strURL1 As String, strURL2 As String
    Dim strURL3 As String, strData As String
    
    LastRow = Sheets("Control").Range("B" & Rows.Count).End(xlUp).Row
    
    For i = 55 To LastRow
        strData = Sheets("Control").Cells(i, 2)
   
        strURL = "URL;http://68.226.77.253/text/NAMSFC/NAM_" & strData & ".txt"
        strURL1 = "URL;http://charlie.wxcaster.com/text/GFSSFC/GFS_" & strData & ".txt"
        strURL2 = "URL;http://www.nws.noaa.gov/cgi-bin/lamp/getlav.pl?sta=" & strData
        strURL3 = "URL;http://weather.uwyo.edu/cgi-bin/wyowx.fcgi?TYPE=metar&DATE=current&HOUR=current&UNITS=A&STATION=" & strData
        
        With Sheets("Sheet1").Range("A1").QueryTable
            .Connection = strURL
            .WebSelectionType = xlAllTables
            .WebFormatting = xlWebFormattingNone
            .WebPreFormattedTextToColumns = False
            .WebConsecutiveDelimitersAsOne = True
            .WebSingleBlockTextImport = False
            .WebDisableDateRecognition = False
            .WebDisableRedirections = False
            .Refresh BackgroundQuery:=False
        End With
    Next
End Sub

Open in new window


Sid
0
 
LVL 42

Expert Comment

by:dlmille
ID: 34934478
Another solution  - sets public variable on open and increments from there...  You might want a routine to zero the RowIncr if you're testing in the middle of all this:

Public sub zeroIncr()
  RowIncr = 0
end sub


And your code would be:

Public Const InitialRow As Integer = 55 'initial row to set
Public RowIncr As Integer
'initially is zero at compile/bind

     Dim strURL, strURL1, strURL2, strURL3, strData
    On Error Resume Next
    'called from Sheet1 where A12 contains - pafb

strData = Sheets("Control").Cells(InitialRow + RowIncr, 2)  

    'change sheets
    Sheets("Sheet1").Activate   'sheet named WebData to hold returned data
   
    'clear last web query
    'Cells.Select
    'Selection.Clear
    'this line will fail if there isn't an existing web query - comment out the first time around...
    'Selection.QueryTable.Delete

    'return to top
    'Cells(1, 1).Select
   
    'get new web data
    strURL = "URL;http://68.226.77.253/text/NAMSFC/NAM_" & strData & ".txt"
    strURL1 = "URL;http://charlie.wxcaster.com/text/GFSSFC/GFS_" & strData & ".txt"
    strURL2 = "URL;http://www.nws.noaa.gov/cgi-bin/lamp/getlav.pl?sta=" & strData
    strURL3 = "URL;http://weather.uwyo.edu/cgi-bin/wyowx.fcgi?TYPE=metar&DATE=current&HOUR=current&UNITS=A&STATION=" & strData
    Range("A1").Select
    With Selection.QueryTable
        .Connection = strURL
        .WebSelectionType = xlAllTables
        .WebFormatting = xlWebFormattingNone
        .WebPreFormattedTextToColumns = False
        .WebConsecutiveDelimitersAsOne = True
        .WebSingleBlockTextImport = False
        .WebDisableDateRecognition = False
        .WebDisableRedirections = False
        .Refresh BackgroundQuery:=False
    End With

 RowIncr = RowIncr + 1

Dave
0
 
LVL 42

Expert Comment

by:dlmille
ID: 34934483
Of course, this assumes the initial row is ALWAYS 55.  If it needs to be determined by the existing range, Sid's approach is the way to go.

Dave
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes how you can use Custom Document Properties to store settings and other information in your workbook so that they will be available the next time you open the workbook.
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa‚Ķ

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question