Excel宏 - 将一列添加到另一列

时间:2017-08-30 21:24:55

标签: excel excel-vba vba

您好我有一个包含以下数据的Excel工作表:

func requestAccess(completionHandler: @escaping (_ accessGranted: Bool) -> Void) {
    switch CNContactStore.authorizationStatus(for: .contacts) {
    case .authorized:
        completionHandler(true)
    case .denied:
        showSettingsAlert(completionHandler)
    case .restricted, .notDetermined:
        store.requestAccess(for: .contacts) { granted, error in
            if granted {
                completionHandler(true)
            } else {
                DispatchQueue.main.async {
                    self.showSettingsAlert(completionHandler)
                }
            }
        }
    }
}

private func showSettingsAlert(_ completionHandler: @escaping (_ accessGranted: Bool) -> Void) {
    let alert = UIAlertController(title: nil, message: "This app requires access to Contacts to proceed. Would you like to open settings and grant permission to contacts?", preferredStyle: .alert)
    alert.addAction(UIAlertAction(title: "Open Settings", style: .default) { action in
        completionHandler(false)
        UIApplication.shared.open(URL(string: UIApplicationOpenSettingsURLString)!)
    })
    alert.addAction(UIAlertAction(title: "Cancel", style: .cancel) { action in
        completionHandler(false)
    })
    present(alert, animated: true)
}

我需要一个宏,它会将未开帐单的添加到< 48 ,即3 + 4 = 7。 然后7将取代4.

我试过了VISIT <48 >48 TOTAL BILLED NOT BILLED 10 4 3 7 3 ,但它没有编译。

1 个答案:

答案 0 :(得分:0)

根据您的问题,我根据要求编写了经过测试和运作的 假设您的Cell 与以下部分中的相同。 (请注意,行可能不同,可能从不同的位置开始)

您可以选择图片中显示的需要处理的行。

enter image description here

    Sub calculate()
    ' Calculates for each row in any selection
    ' Takes value in C and add value in F if value in F is larger than 0 then afterwards makes value in f equal to 0
    ' Asumes that Column "C" have the "Visit" and Column "F" is the "Not Billed" columns

    Dim sel As Range
    Dim rw As Range
    Dim l As Long

        Set sel = Selection

        For Each rw In sel ' Adapt this to however you need to specify the selection you want to work with
            If (Cells(rw.Row, 6).Value > 0) Then ' Test if the value need to be processed
                l = Cells(rw.Row, 3).Value + Cells(rw.Row, 6).Value
                Cells(rw.Row, 6).Value = 0
                Cells(rw.Row, 3).Value = l
                'Cells(rw.Row, 3) would be column C
                'Cells(rw.Row, 6) would be column F
            End If
        Next

    End Sub

运行宏后,您的文件将如下所示:

enter image description here

让我知道它是否适合您。