简体   繁体   中英

How to loop my Current VBA Code

I need to modify with loop my existing VBA. I have a part of website link in Column A. I want to dynamic below this line.

ticjername = Sheet1.Range("A1").Value

I need to loop it, because I want to continue this code until data found in Column A. My Code:

Sub Macro1()
'
' Macro1 Macro
'
' Keyboard Shortcut: Ctrl+q
'

Dim ticjername As String
ticjername = Sheet1.Range("A1").Value
mURL$ = "http://www.example.com=" & ticjername
    With ActiveSheet.QueryTables.Add(Connection:= _
        "URL;" & mURL, Destination:=Range("B1"))
        .Name = " "
        .FieldNames = True
        .RowNumbers = False
        .FillAdjacentFormulas = False
        .PreserveFormatting = True
        .RefreshOnFileOpen = False
        .BackgroundQuery = True
        .RefreshStyle = xlInsertDeleteCells
        .SavePassword = False
        .SaveData = True
        .AdjustColumnWidth = False
        .RefreshPeriod = 0
        .WebSelectionType = xlSpecifiedTables
        .WebFormatting = xlWebFormattingNone
        .WebTables = "1"
        .WebPreFormattedTextToColumns = True
        .WebConsecutiveDelimitersAsOne = True
        .WebSingleBlockTextImport = False
        .WebDisableDateRecognition = False
        .WebDisableRedirections = False
        .Refresh BackgroundQuery:=False
    End With

 Columns("B:C").Select
    Selection.Delete Shift:=xlToLeft
    Columns("B:B").Select
    Selection.SpecialCells(xlCellTypeBlanks).Select
    Selection.Delete Shift:=xlUp
    Range("B1").Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.Cut
    Sheets("Sheet2").Select
    ActiveCell.Select
    ActiveSheet.Paste
    Range("A" & Rows.Count).End(xlUp).Offset(1).Select
End Sub

Try below code

    Dim rowID As Integer
    rowID = 1
    Do

        '<Your code>

        rowID = rowID + 1
    Loop Until Sheet1.Cells(rowID, 1).Value = ""

Credit goes to www.stackoverflow.com

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM