无后卫,ActiveRecord效果最佳

时间:2019-02-27 16:54:40

标签: ruby-on-rails

我正在尝试使用以下代码Rails代码(v3.2)返回最大ID或将其设置为1:

 b = PriceTier.maximum(:id) ||= 1

但出现以下错误:

SyntaxError: unexpected tOP_ASGN, expecting end-of-input

没有记录时。我将如何工作?这是否像查找例外情况(似乎没有例外)那样工作?

1 个答案:

答案 0 :(得分:1)

您不需要第二个等号运算符

 Sub FilterAndCopy2()

    Application.ScreenUpdating = False
    Application.EnableEvents = False
    Application.Calculation = xlCalculationManual


    Dim LastRow As Long, LastRow2 As Long
    Dim TARGetSheet As Worksheet, TKSheet As Worksheet

    Set TARGetSheet = Sheets("2. Select Study-Specific Forms") 'Set sheet where filtered data is
    Set TKSheet = Sheets("3. Worksheet") ' Set Sheet name to copy data to

    LastRow = TARGetSheet.Range("L" & Rows.Count).End(xlUp).Row ' Determine the lastrow of the data to copy
    LastRow2 = TKSheet.Range("A" & Rows.Count).End(xlUp).Row + 1 ' Determine the next empty row in order to paste the data


    With TARGetSheet
        .AutoFilterMode = False

        With .Range("G7", "L" & LastRow)
        .AutoFilter
        .AutoFilter Field:=6, Criteria1:="Yes"
        End With
    End With

     TARGetSheet.Range("G7", "L" & LastRow).Copy
     TKSheet.Range("A" & LastRow2).PasteSpecial (xlPasteAll)

    Application.ScreenUpdating = True
    Application.EnableEvents = True
    Application.Calculation = xlCalculationAutomatic

    End Sub