I have a a piece of code that is being called from a front sheet within a workbook and making reference to two sheets within the work book. I know this code does what I need it to do when I am on the "Data" tab. However when I run it from the "Control Menu" tab it does not populate. I can see where this is failing, because when I look at the line:
If Range("B" & i + 1).Offset(0, -1).Value = 1 And Range("B" & i + 1).Value = "UK" Then
I hover my cursor over the .Value command and box displays 'Empty', so I know that this code is looking at the 'Control Menu' tab even though I am starting my code using the With Sheets("Data") command.
Essentially on the Data tab I have a few hundred rows of data being pulled through and I'm trying to loop through table copy out the data where the ReportID = 1 and the Country = UK and move it to another tab where I have charts linking to.
The full code is below:
With Sheets("Data")
RowCount = .Cells(.Rows.Count, "B").End(xlUp).Row
For i = 1 To RowCount
Range("B1").Offset(1, 0).Select
If Range("B" & i + 1).Offset(0, -1).Value = 1 And Range("B" & i + 1).Value = "UK" Then
ActiveSheet.Cells.Range(Selection, Selection.End(xlToRight)).Select
Selection.Copy
With Sheets("DynamicCharts")
.Range("A" & Cells.Rows.Count).End(xlUp).Offset(1, 0).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
End With
End If
Next i
End With
Any help would be much appreciated.
Thanks in advance