Hi guys,
I had so much help from others here with the last macro and I am hoping someone can help me out with this new one.
What I need this code to do is copy the value in cell B4 in one workbook to cell G6 in the other workbook, and continue copying the value down to the last row. The workbook names will never be the same, neither will the number of rows. The two cells are the same. I have managed to get it to copy the right data to where I need to get it to go, but not to copy down. I pulled some code from my other macro that copied down to the last row, but I am getting "object not defined" errors. Not sure if it is because this macro works across workbooks, and the other was just worksheets.
Would anyone mind taking a look at what I have so far and suggest any changes? Eventually I will need this macro to do much more but I really want this aprt to work before I continue.
Thank you
I had so much help from others here with the last macro and I am hoping someone can help me out with this new one.
What I need this code to do is copy the value in cell B4 in one workbook to cell G6 in the other workbook, and continue copying the value down to the last row. The workbook names will never be the same, neither will the number of rows. The two cells are the same. I have managed to get it to copy the right data to where I need to get it to go, but not to copy down. I pulled some code from my other macro that copied down to the last row, but I am getting "object not defined" errors. Not sure if it is because this macro works across workbooks, and the other was just worksheets.
Would anyone mind taking a look at what I have so far and suggest any changes? Eventually I will need this macro to do much more but I really want this aprt to work before I continue.
Thank you
Code:
Sub LabData()
Dim wb As Workbook
Dim CellCount, FormulaCount As Long
Dim Ws As Worksheet
Dim RangeSource, RangeDest As Range
For Each wb In Workbooks
If wb.Name <> ThisWorkbook.Name Then
Worksheets(1).Range("B4").Copy ThisWorkbook.Sheets(1).Range("G6")
End If
Set Ws = ThisWorkbook.Sheets(1)
CellCount = Ws.Range("A6").End(x1Down).Row ' error on this line
FormulaCount = WorksheetFunction.CountA(Ws.Columns("G6")) ' this line gives same error if I comment line above out
If CellCount <> FormulaCount Then
If FormulaCount > 7 Then Ws.Range("G7:G" & FormulaCount).ClearContents
Set RangeSource = Ws.Range("G6")
Set RangeDest = Ws.Range("G6:G" & CellCount)
RangeDest.Formula = RangeSource.Formula
End If
Next wb
MsgBox "Complete"
End Sub
Last edited: