msquared99
Member
Hello all,
I'm rather new to VBA (Excel 2010) which is why I'm asking this question.
I have a workbook that contains many worksheets within the workbook.
In column A of all the worksheets I am looking for "Total Wages & Salaries" aka TWS and "Total General & Administrative" aka TGA. Ideally I would like to sum TWS and TGA for each worksheet and have the result entered on a new sheet in the active workbook called "Summary".
Of the worksheets I am looking at, the data needed is in columns B, D,G and H. There are blank and hidden rows in the worksheets and they vary in the number of rows. Column B is PTD Actual, column D is PTD Budget, column G is YTD Actual and column H is YTD Budget.
So on the summary sheet column A would be the name of the worksheet, column B would be the sum of each PTD Actual total, column C would be the PTD Budget Total and so on.
The code below pulls in the name of each of the worksheets and a specific cell from each worksheet.
[pre]
[/pre]
Many thanks for your help!
I'm rather new to VBA (Excel 2010) which is why I'm asking this question.
I have a workbook that contains many worksheets within the workbook.
In column A of all the worksheets I am looking for "Total Wages & Salaries" aka TWS and "Total General & Administrative" aka TGA. Ideally I would like to sum TWS and TGA for each worksheet and have the result entered on a new sheet in the active workbook called "Summary".
Of the worksheets I am looking at, the data needed is in columns B, D,G and H. There are blank and hidden rows in the worksheets and they vary in the number of rows. Column B is PTD Actual, column D is PTD Budget, column G is YTD Actual and column H is YTD Budget.
So on the summary sheet column A would be the name of the worksheet, column B would be the sum of each PTD Actual total, column C would be the PTD Budget Total and so on.
The code below pulls in the name of each of the worksheets and a specific cell from each worksheet.
[pre]
Code:
Sub Extract()
Dim whst1 As Worksheet
Dim i As Long
i = 1
For Each wsht1 In ThisWorkbook.Worksheets
If LCase(wsht1.Name) <> LCase("Sheet1") Then
With Worksheets("Sheet1")
.Cells(i, "A").Value = wsht1.Name
.Cells(i, "B").Value = wsht1.Range("B2").Value
End With
i = i + 1
End If
Next
End Sub
I'm pretty sure I'll need something like this to get what I am after but do not know how to incorporate it into my code.
For Each ws In Worksheets
Set rFind = ws.Cells.Find(What:="Total Wages &Salaries", _
LookIn:=xlFormulas, LookAt:=xlPart, _
SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False)
If Not rFind Is Nothing Then
ws.Select
rFind.Select
Exit Sub
End If
Next ws
Many thanks for your help!