Как скопировать ячейки из одной рабочей книги в другую по нескольким критериям

В дополнение к forcats :: fct_infreq, указанному @HolgerBrandl, существует файл forcats :: fct_rev, который меняет порядок факторов.

theTable <- data.frame(
    Position= 
        c("Zoalkeeper", "Zoalkeeper", "Defense",
          "Defense", "Defense", "Striker"),
    Name=c("James", "Frank","Jean",
           "Steve","John", "Tim"))

p1 <- ggplot(theTable, aes(x = Position)) + geom_bar()
p2 <- ggplot(theTable, aes(x = fct_infreq(Position))) + geom_bar()
p3 <- ggplot(theTable, aes(x = fct_rev(fct_infreq(Position)))) + geom_bar()

gridExtra::grid.arrange(p1, p2, p3, nrow=3)             

0
задан Cœur 29 March 2019 в 10:56
поделиться

1 ответ

Это НЕ код НО некоторые рекомендации:

Option Explicit

Sub test()

    Dim wb1 As Workbook, wb2 As Workbook
    Dim LastRow1, LastRow2 As Long
    Dim rng1 As Range, rng2 As Range, Position As Range, cell As Range

    'Set the two workbooks. Keep in mind that code will works only if you have both workbooks open
    Set wb1 = Workbooks("antennalist.xls")
    Set wb2 = Workbooks("rawdata.xls")

    'Let us assume that data appears in Sheet1 & Column A in both workbooks. Find the last row of column A in both Sheets to create our ranges
    With wb1.Worksheets("Sheet1")
        LastRow1 = .Cells(.Rows.Count, "A").End(xlUp).Row
        Set rng1 = .Range("A" & LastRow1)
    End With
    With wb2.Worksheets("Sheet1")
        LastRow2 = .Cells(.Rows.Count, "A").End(xlUp).Row
        Set rng2 = .Range("A" & LastRow2)
    End With

    'Loop rawdata workbook,Sheet 1 & column A and check:
    ' 1.If the values of rawdata workbook,Sheet 1 & column A appears also in antennalist workbook,Sheet 1 & column A
    ' 2.If the value next to them match also (this is for testing purposes so you must change)
    For Each cell In rng2
        If Application.WorksheetFunction.CountIf(rng1, cell.Value) > 0 And cell.Offset(0, 1).Value = .Range("B" & rng1.Row).Value Then
        'If condition met copy from rawdata & paste to antennalist
            wb2.Worksheets("Sheet1").Range("A1:A2").Copy wb1.Worksheets("Sheet1").Range("A1:A2")
        End If
    Next cell

End Sub
0
ответ дан Error 1004 29 March 2019 в 10:56
поделиться
Другие вопросы по тегам:

Похожие вопросы: