View Single Post
 
Old 11-07-2014, 07:38 PM
whatsup whatsup is offline Windows 7 64bit Office 2010 32bit
Competent Performer
 
Join Date: May 2014
Posts: 137
whatsup will become famous soon enough
Default

Here an example how you can insert either a formula or a value from another workbook into your workbook of destination.

With your provided uploads, you will run into an error after the third loop, since your source doesn't provide sufficent Sheets. But it will show you, how you can assemble parts of a path to a working formula, or use them to get values of an open workbook.

Copy the code in a new module and step through the code using F8 while observing the changes in your sheet.
Code:
Sub Get_Data()
Dim lngCol As Long
Dim lngMonth As Long
Dim lngStart As Long
Dim strformula As String
 
Const strCellRef As String = "$F$6"
 
With ActiveSheet
    lngStart = .Cells(2, 1).Value
    lngMonth = Month(.Cells(2, 1).Value)
 
    Do While Month(lngStart + lngCol) = lngMonth
        'Insert formula
        .Cells(2, lngCol + 2).Formula = "='[Source WKB.xlsx]" & Format(lngStart + lngCol, "DD.MM.YY") & "'!" & strCellRef
        'Insert value
        .Cells(2, lngCol + 2).Value = Workbooks("Source WKB.xlsx").Sheets(Format(lngStart + lngCol, "DD.MM.YY")).Range(strCellRef).Value
        lngCol = lngCol + 1
    Loop
End With
 
 
End Sub
Any questions?
Reply With Quote