1

我这里有一些 .xls 电子表格,每个电子表格大约有 1800 行,都充满了来自我的亚马逊商店的产品信息。

我需要更新其类别中每个产品的价格,但所有产品都混杂在一起。我希望我可以创建一个脚本来帮助我。

行格式为:产品名称 | 说明 | 货号 | 条码 | 价格 | 等等等等

我希望在开始时指定一个关键字和价格,然后点击 go,脚本将执行以下操作:

Search the Name (A1) for a keyword of my choice,
If found, update price (E1) with a price of my choice, then start next row (A2)
or If not found move on to (A2) and repeat until the end.

现在将不胜感激任何帮助,并为我节省数小时的麻木复制面食。

干杯

4

3 回答 3

1

嗯……你写宏怎么样?我会指定两个单元格,比如 F1 和 G1,作为您要搜索的内容以及您希望将其更改为的价格,然后执行以下操作:

dim i as integer
dim SearchFor as string
SearchFor=range("F1").value
NewPrice=range("G1").value
dim NewPrice as string
for i=1 to 1800
  if(range("A" & i).value=SearchFor) then
    range("E" & i).value=NewPrice
  endif
next i

我认为这样的事情应该有效。我假设 A 列是名称,E 是您想要更改的价格。

如果做不到这一点,根据电子表格的设置方式,转到标题所在的位置并打开自动过滤器(在许多 Excel 版本中,它位于数据 - 过滤器 - 自动过滤器中)。

于 2013-04-08T15:13:37.263 回答
1

这是类似于用户 1560834 的东西,因为它是 VBA。无论大小,它都会遍历您的整个列表-我也对其进行了测试。这是之前和之后的图像: 变更前 在此处输入图像描述

这是代码:

Sub Price_Update()

    Dim CurrRow As Integer
    Dim CurrCol As Integer
    Dim TargetRow As Integer
    Dim TargetCol As Integer

    Const Text_to_Find = "ABC"
    Const New_Price = 4.45

    CurrRow = 2 ' Start with row 2, not header row
    CurrCol = 1 ' This is column A

    TargetRow = 2 ' Start with row 2, not header row
    TargetCol = 5 ' This is column E

    ' Search through all records until blank found
    While Cells(CurrRow, CurrCol) <> ""

        ' Look for string in column A
        If InStr(1, UCase(Cells(CurrRow, CurrCol)), UCase(Text_to_Find)) > 0 Then
            ' If found, update column E with the new price
            Cells(TargetRow, TargetCol) = New_Price
        End If

        ' Move to the next source and target rows
        CurrRow = CurrRow + 1
        TargetRow = TargetRow + 1

    Wend

End Sub

将其放入 VBA(选择 Developer > Visual Basic),然后更改要查找的文本和价格。按 F5 运行。

在更新真实数据之前,请确保进行备份。

于 2013-04-08T15:30:16.470 回答
0

工作表公式可以做到这一点

在 E 列中,将以下公式从第 1 行放到第 1800 行:

=IF(A:A=$F$1, $G$1, OLD_Price)

(这是一个 IF 列 A=F1,THEN 使用 G1 中的值,ELSE ...块...)

高温高压

菲利普

于 2013-04-09T09:15:42.147 回答