自定义Excel脚本,用1800行更新xls

我在这里有几个.xls的电子表格,每个电子表格都有大约1800行,全部来自我的亚马逊商店的产品信息。

我需要更新每个产品类别的价格,但是所有的产品都混乱了。 我希望我可以创build一个脚本来帮助我。

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

我希望在开始时指定一个关键字和价格,然后按照以下步骤执行脚本:

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. 

任何帮助,将不胜感激现在,并节省我的麻烦复制意大利面的时间和小时。

干杯

这是类似于用户1560834的东西,因为它是VBA。 它会通过你的整个列表,不论大小 – 我也testing过它。 这里是前后图像: 改变之前在这里输入图像说明

代码如下:

 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中(selectDeveloper> Visual Basic),然后更改文本以查找价格。 按F5运行。

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

嗯…你怎么写macros? 我会指定两个单元格,F1和G1,作为你正在search的价格,你想要它改变,并做这样的事情:

 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是你想要改变的价格。

否则,取决于如何设置电子表格,去你的标题,并把自动filter(在许多Excel版本,它是在数据filter – 自动filter)。

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

在E列中将第1行至第1800行的以下公式:

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

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

HTH

菲利普