简体   繁体   中英

Copying Cells with a Specific Value in a Range using a Formula

I am trying to import and maintain a list in excel of all taken fantasy football players in my fantasy league and their avg pts per week. I can get this information from yahoo at 25 players per page, so I have set up an excel workbook with each page importing a weblink into excel with 25 players (10 pages total)

The idea is that every week I can simply refresh all of the pages into excel and then have another sheet in the same workbook that goes through all of the worksheets and puts them into a nice list which I can manipulate and play with. It would essentially be:

Player Name | Position | Team Name | AVG PTS

Unfortunately the information imported is a little variable so I cannot specifically reference absolute cells. This is because there may or may not be an extra row between players with their injury status.

What I do know is that the player name is in column b, starting within the range B160 and ending at a maximum B250. Each player's name in column b can be isolated with a ctrl+f for " - "

What I want to do is set up a formula on a separate sheet in the workbook that will:

  1. search this range on the worksheets with the imported data,
  2. find all strings with a " - " in this range
  3. copy/return full string of cell and nothing else

I'm not sure if this is possible with a formula, and I haven't had any luck looking at other posts on here.

Here is a link to a truncated version of what I'm doing using google docs (I feel like people would feel funny downloading some random excel file:

https://docs.google.com/spreadsheet/ccc?key=0AvLwUKmn33T6dHhGcEVwWC1KdXpMblJoRGJzMlNWWlE&usp=sharing

An easy way if you just have a couple of sheets, is to filter the column, and type in " - " (without quotes) in filter search. This works for 2007+. Copy and paste the visible cells only to your main workbook.

You could also use VBA to do this:

Dim sMain As String
Dim sImported As String, lLen As Long
Dim sStart As String
sMain = "ALL TAKEN PLAYERS AVG" 'name of your main sheet
sMainCol = "A" 'column your player names will go in
sImported = "Imported Data " 'string that player sheets start with
lLen = Len(sImported)
sStart = "B160" 'starting cell for imported data

Dim ws As Worksheet
Dim rPlayers As Range, cell As Range
Dim counter As Long

counter = 5 'starting row to fill out players

For Each ws In Worksheets
    If Left(ws.Name, lLen) = sImported Then
        ws.Activate
        Set rPlayers = Range(Range(sStart), Range(sStart).End(xlDown))
        For Each cell In rPlayers
            If InStr(1, cell.Value, " - ") > 0 Then
                Sheets(sMain).Range(sMainCol & counter).Value = cell.Value
                counter = counter + 1
            End If
        Next cell
    End If
Next ws

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM