PDA

View Full Version : [SOLVED:] Writing formula at the end of selection



nirvehex
09-29-2014, 11:56 AM
Hi,

I have a VBA code:

Code:



Sheets("Recommendations").Select
Range("A3").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
Sheets("Client Pre-Bid").Select
Range("A2").Select
Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats, Operation:= _
xlNone, SkipBlanks:=False, Transpose:=False


It pastes in data from one sheet tab to another. The range varies in number of rows. Once the data is pasted, how do I add in the formula "=countif(A2:end of last row pasted,"Yes") into the row below the last row pasted?

Thank you!

nirvehex
09-29-2014, 12:16 PM
Nevermind, got it!



Sheets("Recommendations").Select
Range("A3").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
Sheets("Client Pre-Bid").Select
Range("A2").Select
Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats, Operation:= _
xlNone, SkipBlanks:=False, Transpose:=False
LR = Range("A" & Rows.Count).End(xlUp).Row
Range("A" & LR + 1).Formula = "=COUNTIF(A2:A" & LR & ",""Yes"")"

nirvehex
09-29-2014, 12:49 PM
What if I want to do a sum of the column instead of a countif?

Would it be:




Range("A" & LR + 1).Formula = "=SUM(A2:A" & LR ")"



This doesn't seem to work. Do I have a quote in the wrong spot?

nirvehex
09-29-2014, 12:51 PM
Nevermind, got it.



Range("A" & CMPR + 1).Formula = "=SUM(A2:A" & CMPR & ")"