Writing formula at the end of selection

nirvehex

Active Member
Joined
Jul 27, 2011
Messages
486
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?
 

Some videos you may like

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!

bbott

Well-known Member
Joined
Feb 5, 2010
Messages
2,350
Code:
    Range("A" & Range("A" & Rows.Count).End(xlUp).Row).Offset(2, 0).Formula _
        = "=COUNTIF(A2:A" & Range("A" & Rows.Count).End(xlUp).Row & ",""Yes"")"
 

VoG

Legend
Joined
Jun 19, 2002
Messages
63,650
Try

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
    LR = Range("A" & Rows.Count).End(xlUp).Row
    Range("A" & LR + 1).Formula = "=COUNTIF(A2:A" & LR & ",""Yes"")"
 

Watch MrExcel Video

Forum statistics

Threads
1,109,360
Messages
5,528,233
Members
409,809
Latest member
VICKRAM

This Week's Hot Topics

  • Change military grades into rank
    Afternoon all Need help with formula that will change military rank (i.e. 1, 2, 3 into Amn, A1C, SrA). Running IF formula that does not work...
  • VBA COUNTIF SOLUTION
    Hi The following are the errors spread across the several columns from E to Q ie. 13 columns across several sheets with more than 500 rows per...
  • INSERT ROW WITH SPECIFIS TEXT IN A COLUMN
    Hi All! How can identify that that the row to be inserted has to be inserted before 1st row with specific text in column F. If I record the...
  • Auto-Create a monthly Sign in sheet for preschool students
    The image below is what each page looks like. Above is space for the "Child Name" "Month" "Class" School days are obviously Monday-Friday but...
  • VBA vlookup multiple results
    Hi folks, Hopefully someone out there can help. I have a list to vlookup which works (ish). the lookup only picks up the first instance of the...
  • Extract values for earliest/latest times
    I am trying to put together a formula to get the earliest start time, the latest end time from column A for each person in Column B-F without the...
Top