I am a complete noob with excel VBA so hopefully one of you guys can help me with this. Basically all I want to do is to write a VBA code to select and copy all dates data with the header "Date", and stack paste them in one column. There will be more funds' value and dates data to add in in the future so the column for the dates data may not be fixed (e.g if I insert data for a new fund in column A, the current dates data under Column A may shift to column C, but the header "Date", "FundX Value" will always be there). The current code I've got so far is not scalable -I have to clearly define the arrays (1,4,8) that contain the dates data, but like I said, with more data to be added, the arrays may change. Is there anyways to make it dynamic and scalable?
Many thanks!
Sub test()
Dim r%, i%
Dim arr, brr
Dim d As Object
Set d = CreateObject("scripting.dictionary")
With Worksheets("sheet1")
For Each j In Array(1, 4, 8)
r = .Cells(.Rows.Count, j).End(xlUp).Row
arr = .Cells(2, j).Resize(r - 1, 1)
For i = 1 To UBound(arr)
d(arr(i, 1)) = Empty
Next
Next
.Range("k2:k" & .Rows.Count).Clear
.Range("k2").Resize(d.Count, 1) = Application.Transpose(d.keys)
End With
End Sub