我需要使用循环修改现有的VBA。我在A栏中有一部分网站链接。我想在这一行下方动态。
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 :(得分:0)
尝试以下代码
Dim rowID As Integer
rowID = 1
Do
'<Your code>
rowID = rowID + 1
Loop Until Sheet1.Cells(rowID, 1).Value = ""
来自www.stackoverflow.com