2013-04-08 18 views
1

我這裏有幾個.xls的電子表格,每一個在每個約1800行,無不洋溢着從我的亞馬遜商店的產品信息更新XLS。定義Excel腳本與1800線

我需要更新對他們的每類單品價格,但所有的產品都混亂了。我希望我能夠創建一個腳本來幫助我。

行格式有云:產品名稱|說明| 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. 

任何幫助將不勝感激,現在,救我小時和幾個小時麻木複製意大利麪。

乾杯

回答

1

下面是一些在類似於用戶1560834它的VBA。無論大小如何,它都會遍歷整個列表 - 我也對其進行了測試。這裏是之前和圖像後: Before changes enter image description here

下面的代碼:

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將這個(選擇開發> Visual Basic中),然後更改找到的文本和價格。按F5運行。

您更新您的真實數據之前,請確保您的備份。

+0

完美。你先生是個傳奇人物。 與VB一起工作了很多,只是在使用Excel時不確定某些事情。再次歡呼哥們。 – 2013-04-09 12:25:03

+0

我的榮幸 - 我與VBA合作過很多,但主要是在Access中 - 在Excel中工作很有趣 - 幫助建立我的技能 – cardmagik 2013-04-09 12:36:17

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版本中,位於數據篩選器 - 自動篩選器中)。

0

工作表公式可以做到這一點

列E把以下式從行1至1800:

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

(這是一個IF柱A = F1,則在G1使用值,ELSE ... ...塊)

HTH

菲利普