I have a spreadsheet that has broad groups in column A and then specific data points in column B (with more data throughout those specific rows). It looks very roughly like this:
A B C D E F
Group Name Weight Gross Net Contribution
Equity 25% 10% 8% .25
IBM 5% 15% 12%
AAPL 7% 23% 18%
Fixed Income 25% 5% 4% .17
10 Yr Bond 10% 7% 5%
Emerging Mrkts
I want my macro to scroll through column A until it finds a "Group" (e.g. Equity) and then have it spit out the name as well as some other data for each specific holding within every group.
I have started writing this macro, and have a procedure (that works) and a function. But I can't get the function to work. Can you take a look and tell me what you see wrong? Thanks
Here is my code:
Sub Demo1()
Dim Ptr As Integer
Ptr = 12
ActiveSheet.Cells(1, Ptr).Select
Dim Wb As Workbook
Set Wb = ThisWorkbook
Dim Wb2 As Workbook
For Each Wb2 In Application.Workbooks
Wb2.Activate
Next
Set Wb2 = ActiveWorkbook
' Set Wb = ActiveWorkbook
Wb.Activate
'Sheets("Attribution").Select
ActiveSheet.Cells(Ptr, 2).Select
Selection.Copy
' Sheets("F2 perf Chart").Range("E7") = ActiveSheet.Cells(12, 2).Value
'Set Wb2 = ActiveWorkbook
Wb2.Activate
ActiveSheet.Cells(1, Ptr).Select
Wb2.Sheets("F2 perf Chart").Range("E7").Select
ActiveSheet.Paste
Set Wb = ActiveWorkbook
Range("M12").Copy
Set Wb2 = ActiveWorkbook
Wb2.Sheets("F2 perf Chart").Range("F7").Select
ActiveSheet.Paste
Set Wb = ActiveWorkbook
Range("D12").Copy
Set Wb2 = ActiveWorkbook
Wb2.Sheets("F2 perf Chart").Range("G7").Select
ActiveSheet.Paste
End Sub
And for the function:
Function NumBlankCells(Rownum As Integer) As Integer
Dim RetVar As Integer
Set RetVar = 0
Dim rRng As Object
rRng = Sheets("Attribution").Cells(Rownum + 1, 1)
While IsEmpty(rRng.Value)
RetVar = RetVar + 1
rRng = Sheets("Attribution").Cells(Rownum + RetVar + 1, 1)
Loop
MsgBox RetVar
NumBlankCells = RetVar
End Function
EDIT:
So Workbook 1 ("Attribution") is all this data that has been exported from a program. Workbook 2 ("F2 perf Chart") is a template that I use to self-populate a graph that is used in a quarterly report. An example of one of the data subsets I am trying to pull is the Name, the Weight, and then the Net Return("IBM, 5%, 12%") - and then I am pasting it into Workbook 2, in a different order ("IBM, 12%, 5%"). I am trying to get this to run through and copy-paste each data point under the Name column, and my function is an attempt to use the blank spaces in between each group to tell itself that it should skip these blank rows.