[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Run Macro

Posted on 2011-02-19
3
Medium Priority
?
280 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’s Wrong with Your Cloud Strategy ?

Even as many CIOs are embracing a cloud-first strategy, the reality is that moving to the cloud is a lengthy process and the end-state is likely to be a blend of multiple clouds—public and private. Learn why multicloud solutions matter in this webinar by Nimble Storage.

Question has a verified solution.

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

This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …

650 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