所以我试图整理帐户。
我的列数很少:C是我的银行的每笔交易的信息,可以包含例如这个词'汽油'或者' atm'或者' paypal' 在许多其他关键词组中。
我想创建一个通过C列的宏,搜索' * Paypal',如果找到它,就会发现' Paypal'进入同一行的D列。
另一个例子 - 如果它找到了B / CARD PLAT VISA' C58,然后我喜欢信用卡付款'用D58写的。我试图根据我发现/调整删除列的旧宏来解决它!
类似的东西:
Dim c As Range
Dim SrchRng
Set SrchRng = ActiveSheet.Range("C1", ActiveSheet.Range("C65536").End(xlUp))
Do
Set c = SrchRng.Find("petrol", LookIn:=xlValues)
If Not c Is Nothing Then
//SOMETHING GOES HERE?
Loop While Not c Is Nothing
你可能会说,我对此并不擅长。
我的最终目标是能够从这些标题中输出我每个月/每年在每个类别中花费和赚取的金额。它应该使自己的生活稍微容易一些。
答案 0 :(得分:1)
OK!所以在CoRrRan的帮助下,一些宏的自我录制和一些谷歌,我已经设法创造了我所需要的。
Sub OrganiseCategories()
Dim FoundRange As Range, FirstAddress As String, Searchterm As Variant, Searchresult As Variant
Searchterm = InputBox("What term would you like to search for?")
Searchresult = InputBox("What category would you like to set for this term?")
With Range("C:C")
Set FoundRange = .Find(What:=Searchterm, LookIn:=xlValues, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False)
FirstAddress = FoundRange.Address
Do
FoundRange.Offset(0, 1).Value2 = Searchresult
Set FoundRange = .FindNext(FoundRange)
Loop While Not FoundRange Is Nothing And FoundRange.Address <> FirstAddress
End With
End Sub
这为我提供了一个用于输入非精确搜索词的输入框,以及一个用于选择用于放置搜索结果的类别的输入框:每次我想要进行新搜索时都比更改代码容易得多。我可以在没有输入框的情况下为汽油,签证,PayPal等术语创建多个“默认”搜索,作为单独宏的基础。
答案 1 :(得分:0)
这可以帮助你进一步:
Sub OrganiseCategories()
Dim FoundRange As Range, FirstAddress As String
With Range("B:B")
Set FoundRange = .Find("Paypal", , xlValues, xlWhole, , , False)
FirstAddress = FoundRange.Address
Do
FoundRange.Offset(0, 1).Value2 = "PayPal"
Set FoundRange = .FindNext(FoundRange)
Loop While Not FoundRange Is Nothing And FoundRange.Address <> FirstAddress
End With
End Sub
Ron de Bruin有一个很好的页面: http://www.rondebruin.nl/win/s9/win006.htm