Vba 识别它,然后移动它(宏)
我有一个化学项目,提供一份化合物元素的清单 现在我发现了一个网站,它给了我一个很长的元素列表: 我已经做了这个代码,但它不工作Vba 识别它,然后移动它(宏),vba,excel,Vba,Excel,我有一个化学项目,提供一份化合物元素的清单 现在我发现了一个网站,它给了我一个很长的元素列表: 我已经做了这个代码,但它不工作 Sub move() Dim list As Range Set list = Range("A1:A2651") For Each Row In list.Rows If (Row.Font.Regular) Then Row.Cells(1).Offset(-2, 1) = Row.
Sub move()
Dim list As Range
Set list = Range("A1:A2651")
For Each Row In list.Rows
If (Row.Font.Regular) Then
Row.Cells(1).Offset(-2, 1) = Row.Cells(1)
End If
Next Row
End Sub
你能帮我跑吗?您可以拥有自己的ofc算法。假设列表始终采用相同的格式(即复合名称、空行、复合符号、空行),此快速代码将起作用:
Sub move()
Dim x As Integer
x = 3
With ActiveSheet
Do Until x > 2651
.Cells(x - 2, 2).Value = .Cells(x, 1).Value
.Cells(x, 1).ClearContents
x = x + 4
Loop
End With
End Sub
运行之后,您可以对A:B列进行排序,以删除空格
在尝试了原始代码之后,我意识到问题出在.regular属性值上。我以前没有见过.regular,因此将其改为not.bold,并忽略空白条目,然后添加了一行以清除复制的单元格内容。这与原始代码非常相似,仅供参考:
Sub get_a_move_on()
Dim list As Range
Set list = ActiveSheet.Range("A1:A2561")
For Each Row In list.Rows
If Row.Font.Bold = False And Row.Value <> "" Then
Row.Cells(1).Offset(-2, 1) = Row.Cells(1)
Row.Cells(1).ClearContents
End If
Next Row
End Sub
Sub get_a_move_on()
变暗列表作为范围
Set list=ActiveSheet.Range(“A1:A2561”)
对于列表中的每一行。行
如果Row.Font.Bold=False且Row.Value为“”,则
行单元格(1).偏移量(-2,1)=行单元格(1)
行。单元格(1)。清除内容
如果结束
下一排
端接头
这是一个化合物列表,不是元素,元素周期表中只有大约120种元素 通过XHR和RegEx检索所需数据的另一种方法:
Sub GetChemicalCompoundsNames()
Dim sRespText As String
Dim aResult() As String
Dim i As Long
' retrieve HTML content
With CreateObject("MSXML2.XMLHTTP")
.Open "GET", "https://quizlet.com/18087424", False
.Send
sRespText = .responseText
End With
' regular expression for rows
With CreateObject("VBScript.RegExp")
.Global = True
.MultiLine = True
.IgnoreCase = True
.Pattern = "qWord[^>]*?>([\s\S]*?)<[\s\S]*?qDef[^>]*?>([\s\S]*?)<"
With .Execute(sRespText)
ReDim aResult(1 To .Count, 1 To 2)
For i = 1 To .Count
With .Item(i - 1)
aResult(i, 1) = .SubMatches(0)
aResult(i, 2) = .SubMatches(1)
End With
Next
End With
End With
' output to the 1st sheet
With Sheets(1)
.Cells.Delete
Output .Range("A1"), aResult
End With
End Sub
Sub Output(oDstRng As Range, aCells As Variant)
With oDstRng
.Parent.Select
With .Resize( _
UBound(aCells, 1) - LBound(aCells, 1) + 1, _
UBound(aCells, 2) - LBound(aCells, 2) + 1 _
)
.NumberFormat = "@"
.Value = aCells
.Columns.AutoFit
End With
End With
End Sub
Sub-GetChemicalCompoundsNames()
将文本设置为字符串
Dim aResult()作为字符串
我想我会坚持多久
'检索HTML内容
使用CreateObject(“MSXML2.XMLHTTP”)
.打开“获取”https://quizlet.com/18087424”“错
.发送
sRespText=.responseText
以
'行的正则表达式
使用CreateObject(“VBScript.RegExp”)
.Global=True
.MultiLine=True
.IgnoreCase=True
.Pattern=“qWord[^>]*?>([\s\s]*?)]*?>([\s\s]*?)请共享网站URL。请描述“它不起作用”的含义?