2016-06-12 18 views
0

我需要修改循環我現有的VBA。我在A列中有一部分網站鏈接。我想在該行下方動態顯示。如何循環我當前的VBA代碼

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

我需要循環,因爲我要到A列中 發現數據我的代碼繼續驗證碼:

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 
+0

嗨。你試圖達到的目標並不是特別清楚。請完全解釋你的目標是什麼,以便我們可以幫你解決問題? – Dave

+0

我在ColumnA中有鏈接的一部分。我希望第一個代碼用於RangeA1,然後是A2,A3並且它繼續,直到在ColumnA中找到數據爲止 – Hafigur

+0

您不僅要動態更改鏈接部分,還需要更改目標範圍:B1。請描述或顯示生成的查詢表數據的行/列大小。 – Parfait

回答

0

試試下面的代碼

Dim rowID As Integer 
    rowID = 1 
    Do 

     '<Your code> 

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

幸得到www.stackoverflow.com

+0

請告訴我關於此行ticjername = Sheet1.Range(「A1」)。值 – Hafigur

+0

'ticjername = Sheet1.Range(「A1」)。Value獲取單元格「A1」的值並存儲在變量ticjername中'。 –

+0

我解決了您的問題嗎? –