Hello all,
I think this is my second time posting...maybe first!
I have a spreadsheet that has information in it that will change, the columns will get greater and fewer in number as it comes from an Access Database. The number of rows will remain, always ending at 1202.
Anyway, what I'm trying to figure out is how to get VBA to insert a formula above any cell that has the text "QAAQ" in it.
[table="width: 500, class: grid, align: center"]
[tr]
[td]1[/td]
[td]A[/td]
[td]B[/td]
[td]C[/td]
[td]D[/td]
[td]E[/td]
[td]F[/td]
[td]G[/td]
[td]H[/td]
[td]I[/td]
[td]J[/td]
[td]K[/td]
[td]L[/td]
[/tr]
[tr]
[td]2[/td]
[td][/td]
[td][/td]
[td][/td]
[td][/td]
[td][/td]
[td][/td]
[td][/td]
[td][/td]
[td][/td]
[td][/td]
[td][/td]
[td][/td]
[/tr]
[tr]
[td]3[/td]
[td]REF[/td]
[td]NUM[/td]
[td]NAME[/td]
[td]QAAQ01a[/td]
[td]QAAQ01b[/td]
[td]QAAQ02[/td]
[td]QAAQ02a[/td]
[td]Memo 01[/td]
[td]Memo 02[/td]
[td][/td]
[td]Q Error[/td]
[td]PA Error[/td]
[/tr]
[tr]
[td]4[/td]
[td]125[/td]
[td]544[/td]
[td]J Bloggs[/td]
[td]1[/td]
[td]2[/td]
[td]1[/td]
[td]1[/td]
[td]2[/td]
[td]2[/td]
[td][/td]
[td]abc[/td]
[td]abc[/td]
[/tr]
[/table]
What I think I need is a loop that tests to see if the cell on Row 2 contains "QAAQ*" and if true, inserts "=COUNTIF(from row 3 to row 1202?,2)" in row 1 above the cell.
Does that make sense? I know "from row 3 to row 1202" is not right. but hope I'm making sense?
this is what I have so far:
Thank you in advance! Please let me know if I need to be clearer, or if any further information is required!
I think this is my second time posting...maybe first!
I have a spreadsheet that has information in it that will change, the columns will get greater and fewer in number as it comes from an Access Database. The number of rows will remain, always ending at 1202.
Anyway, what I'm trying to figure out is how to get VBA to insert a formula above any cell that has the text "QAAQ" in it.
[table="width: 500, class: grid, align: center"]
[tr]
[td]1[/td]
[td]A[/td]
[td]B[/td]
[td]C[/td]
[td]D[/td]
[td]E[/td]
[td]F[/td]
[td]G[/td]
[td]H[/td]
[td]I[/td]
[td]J[/td]
[td]K[/td]
[td]L[/td]
[/tr]
[tr]
[td]2[/td]
[td][/td]
[td][/td]
[td][/td]
[td][/td]
[td][/td]
[td][/td]
[td][/td]
[td][/td]
[td][/td]
[td][/td]
[td][/td]
[td][/td]
[/tr]
[tr]
[td]3[/td]
[td]REF[/td]
[td]NUM[/td]
[td]NAME[/td]
[td]QAAQ01a[/td]
[td]QAAQ01b[/td]
[td]QAAQ02[/td]
[td]QAAQ02a[/td]
[td]Memo 01[/td]
[td]Memo 02[/td]
[td][/td]
[td]Q Error[/td]
[td]PA Error[/td]
[/tr]
[tr]
[td]4[/td]
[td]125[/td]
[td]544[/td]
[td]J Bloggs[/td]
[td]1[/td]
[td]2[/td]
[td]1[/td]
[td]1[/td]
[td]2[/td]
[td]2[/td]
[td][/td]
[td]abc[/td]
[td]abc[/td]
[/tr]
[/table]
What I think I need is a loop that tests to see if the cell on Row 2 contains "QAAQ*" and if true, inserts "=COUNTIF(from row 3 to row 1202?,2)" in row 1 above the cell.
Does that make sense? I know "from row 3 to row 1202" is not right. but hope I'm making sense?
this is what I have so far:
Code:
Sub InsertFormulas2()
Dim wbOpen As Workbook
Dim r As Range
Dim lastcol As Integer
Set wbOpen = Workbooks.Open("C:\NAT\BUS\PAY\PAMPD\" & Range("ProjectTitle") & "\Extraction Data\Latest Extraction Data.xlsx")
Worksheets("qryCompletedCases").Activate
ActiveSheet.UsedRange.Copy
Workbooks("Latest Extraction Data.xlsx").Close
Worksheets("Completed").Activate
ActiveSheet.Paste Destination:=Worksheets("Completed").Range("A2")
Set r = ActiveSheet.Range("2:2").Find(what:="QAAQ", Lookat:=xlPart)
'If Not r Is Nothing Then r.Offset(1).Formula = uhhhhhh
With ActiveSheet
lastcol = .Cells(.Columns.Count, "A").End(xlToRight).Column
End With
End Sub
Thank you in advance! Please let me know if I need to be clearer, or if any further information is required!