Goldylocks
New Member
- Joined
- Aug 26, 2014
- Messages
- 3
Hi
As a newbie I've gone through a heap of posts, but I cant quite string the code together for this one.
Context: I have a series of budget templates worksheets that are generated from a list of project codes in column B on a sheet called "Tx project list MYPD 4" - can be up to 200 sheets. These will be filled in after which I need to collate the data and form one report to be uploaded into SAP.
I can generate the templates.
It looks like I need a routine to loop through the budget sheets and check the first variable i.e. IF DB65 > 0 which will then call a subroutine to do the work if the value is > 0.
I've been using something like this:
Dim lastrow As Long
Dim sapsheet As Worksheet
Dim strWsName As String
Dim listsheet As Worksheet
Dim rngCell As range
Set sapsheet = ThisWorkbook.Sheets("SAP upload file")
Set listsheet = ThisWorkbook.Sheets("Tx project list MYPD 4")
'1st clean out old data
sapsheet.range("a11
10000").ClearContents
'the project list loop
Dim strSheetActive As String: strSheetActive = ActiveSheet.Name
Application.ScreenUpdating = False
With listsheet
For Each rngCell In .range("b2:b" & .range("b" & .Rows.Count).End(xlUp).Row)
If Trim(rngCell.Value) <> vbNullString And ActiveSheet.range("DB64").Value > 0 Then Call MacroToCollateData(rngCell.Value)
Next rngCell
End With
Application.Goto sapsheet.Cells(1)
Application.ScreenUpdating = True
Set rngCell = Nothing
End Sub
The loop seems to be working OK, but I cant build the subroutine "MacroToCollateData" to do the stuff I describe in steps 3 - 8
Please can someone help me out.
Many Thanks
As a newbie I've gone through a heap of posts, but I cant quite string the code together for this one.
Context: I have a series of budget templates worksheets that are generated from a list of project codes in column B on a sheet called "Tx project list MYPD 4" - can be up to 200 sheets. These will be filled in after which I need to collate the data and form one report to be uploaded into SAP.
- First I need to clear old data in Reporting Sheet that I will be repopulating called "SAP upload file"
- Then I need to loop through all of the new budget sheets and
- Check to see if there is any data on the project sheet (by simply checking a single cell with a total in it - "DB64")
- If the value is zero, I move on to the next sheet
- If the value is > 0 Then
- Check through 2 ranges "CT11:CZ40" & " CT43:CZ62" to find which cells are > 0
- For each cell in those ranges > 0 find (a) the corresponding Financial Year Code, which is in cell (r10, same column) & (b) Project Code, which is in cell (B4) of each sheet & (c) GL Code which is in "same row, column E" & (d) range of 12 cells which will be offset from active cell (same row, 86 columns to left)
- For each cell > 0 I need to copy these four (a) & (b) & (c) & (d) and paste them into a different sheet "SAP upload file" in the last available row with (a) in column "A" & (b) in column B and (c) in column C and (d) in column E
I can generate the templates.
It looks like I need a routine to loop through the budget sheets and check the first variable i.e. IF DB65 > 0 which will then call a subroutine to do the work if the value is > 0.
I've been using something like this:
Dim lastrow As Long
Dim sapsheet As Worksheet
Dim strWsName As String
Dim listsheet As Worksheet
Dim rngCell As range
Set sapsheet = ThisWorkbook.Sheets("SAP upload file")
Set listsheet = ThisWorkbook.Sheets("Tx project list MYPD 4")
'1st clean out old data
sapsheet.range("a11
'the project list loop
Dim strSheetActive As String: strSheetActive = ActiveSheet.Name
Application.ScreenUpdating = False
With listsheet
For Each rngCell In .range("b2:b" & .range("b" & .Rows.Count).End(xlUp).Row)
If Trim(rngCell.Value) <> vbNullString And ActiveSheet.range("DB64").Value > 0 Then Call MacroToCollateData(rngCell.Value)
Next rngCell
End With
Application.Goto sapsheet.Cells(1)
Application.ScreenUpdating = True
Set rngCell = Nothing
End Sub
The loop seems to be working OK, but I cant build the subroutine "MacroToCollateData" to do the stuff I describe in steps 3 - 8
Please can someone help me out.
Many Thanks