2011-08-05 8 views
0

我承認我對Excel VBA完全陌生。目前,我負責根據網站上自動生成的數據表格生成數據摘要。我已經想好如何將數據刮到我的Excel上了。使用VBA宏獲取刮取的數據並根據特定值創建表格

擦傷的數據格式如下東西:

TYPE | Number_Days_Logged | (一幫行(數據6-7項)的其他重要列|

我現在需要做的是以下

我需要的,如果語句或做對比的有兩種。例如0和1.我真的只需要輸入'1',所以我需要過濾出'type'0,然後我需要檢查「number_days_logged」,如果這個數字是< = 1,我需要將它添加到其他條目的表中,然後我需要檢查「number_days_logged」條目> = 85和< 100.這些結果將需要放入第二個表中。需要對值> = 100進行相同操作。

所以最後我需要三張不同的表格,第一個用綠色格式,然後是橙色,最後是紅色。每個表都需要用上面的信息標題,儘管我真的只需要每行中特定列的數據。 (每一行都有標籤,我只需要特定的幾列)

這對我來說似乎難以置信的複雜,但我願意學習。如果任何人都能以正確的方向刺激我,或者讓它更簡單,我將不勝感激。我可以根據需要添加任何其他細節。

+0

請記住upvote /接受任何你發現有幫助的答案。對那些花時間回答您的問題的人表示認可。 – aevanko

回答

1

我認爲select語句非常清晰,它們往往也運行得更快一些。

dim typeRange as range 
set typeRange = range(cells(startRow,col),cells(stopRow,col)) 
dim entry as range 
dim currentRow as integer 
for each entry in typeRange 
    currentRow = entry.Row 
    if entry.value=1 then 
     select case cells(currentRow,'Number_Days_Logged's column').value 
      case is<=1 
       'copy and paste or transcribe the cells however you need them done. 
      case is<85 
       'do nothing 
      case is<100 
       'copy and paste or transcribe the cells however you need them done. 
      case is>=100 
       'copy and paste or transcribe the cells however you need them done. 
     end select 
    end if 
next 
+0

謝謝你們兩位。我在此期間做的是使用「記錄宏」功能。我想要的作品,但不是很有說服力,也不能重複使用。對於最近的大學畢業生來說,任何建議的資源都可以解決工作環境的問題?再次感謝你們。 – pacman326

+0

只需提問,花點時間,思考替代方案,瀏覽菜單並獲得Googleing的真正優勢。最後一個是真正的技能。 – Brad

0

您將首先使用您想要的顏色和(對於此代碼)設置數據的命名範圍。我可能也會爲你的表使用命名的範圍。這是VBA代碼的骨架。

Dim testrow As Range 

For Each testrow in ActiveSheet.Range("Scraped Data") 
    If testrow.Cells(1) = 1 Then 
    If testrow.Cells(2) <= 1 Then 
     <add to 0-days table> 
    ElseIf testrow.Cells(2) >= 85 AND testrow.Cells(2) < 100 Then 
     <put in 2nd table> 
    ElseIf testrow.Cells(2) >= 100 Then 
     <put in third table> 
    End If 
    End If 
Next testrow 
相關問題