Hi
I added the indirect function to a formula in VBA, but the macro stops at the 'activecell.formula' line below.
I suspect that it's because the VBA editor doesn't like one of the inverted commas?
Can anyone spot the issue here, please?
The sample data this runs on is below:
Sheet 1 has two columns, with data starting in A1, as per below:
[TABLE="width: 128"]
<colgroup><col width="64" span="2" style="width:48pt"> </colgroup><tbody>[TR]
[TD="width: 64"]Number[/TD]
[TD="width: 64"]Count[/TD]
[/TR]
[TR]
[TD="align: right"]1[/TD]
[TD="align: right"]2[/TD]
[/TR]
[TR]
[TD="align: right"]2[/TD]
[TD="align: right"]1[/TD]
[/TR]
[TR]
[TD="align: right"]3[/TD]
[TD="align: right"]0[/TD]
[/TR]
</tbody>[/TABLE]
Sheet 2 has one column, with data starting in A1, as per below.
[TABLE="width: 64"]
<colgroup><col width="64" style="width:48pt"> </colgroup><tbody>[TR]
[TD="width: 64, align: right"]1[/TD]
[/TR]
[TR]
[TD="align: right"]1[/TD]
[/TR]
[TR]
[TD="align: right"]2[/TD]
[/TR]
</tbody>[/TABLE]
The macro should insert a count if into cell B2 of Sheet 1, then drag it down.
TIA
I added the indirect function to a formula in VBA, but the macro stops at the 'activecell.formula' line below.
I suspect that it's because the VBA editor doesn't like one of the inverted commas?
Can anyone spot the issue here, please?
The sample data this runs on is below:
Sheet 1 has two columns, with data starting in A1, as per below:
[TABLE="width: 128"]
<colgroup><col width="64" span="2" style="width:48pt"> </colgroup><tbody>[TR]
[TD="width: 64"]Number[/TD]
[TD="width: 64"]Count[/TD]
[/TR]
[TR]
[TD="align: right"]1[/TD]
[TD="align: right"]2[/TD]
[/TR]
[TR]
[TD="align: right"]2[/TD]
[TD="align: right"]1[/TD]
[/TR]
[TR]
[TD="align: right"]3[/TD]
[TD="align: right"]0[/TD]
[/TR]
</tbody>[/TABLE]
Sheet 2 has one column, with data starting in A1, as per below.
[TABLE="width: 64"]
<colgroup><col width="64" style="width:48pt"> </colgroup><tbody>[TR]
[TD="width: 64, align: right"]1[/TD]
[/TR]
[TR]
[TD="align: right"]1[/TD]
[/TR]
[TR]
[TD="align: right"]2[/TD]
[/TR]
</tbody>[/TABLE]
The macro should insert a count if into cell B2 of Sheet 1, then drag it down.
TIA
Code:
Sub Macro2()'Populate Data
Range("b2").Select
ActiveCell.Formula = "=COUNTIF(INDIRECT(""'Sheet2'!A:A"",'Sheet1'!A1)"
Range("B2:B" & Range("A" & Rows.Count).End(xlUp).Row).Formula = "=COUNTIF(INDIRECT(""'Sheet2'!A:A"",'Sheet1'!A1)"
End Sub