Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vba 根据相邻单元格中的条件在范围内的下一个空白单元格中粘贴数据_Vba_Excel - Fatal编程技术网

Vba 根据相邻单元格中的条件在范围内的下一个空白单元格中粘贴数据

Vba 根据相邻单元格中的条件在范围内的下一个空白单元格中粘贴数据,vba,excel,Vba,Excel,我是一个使用VBA的初学者 我想将值复制并粘贴到特定范围内第一个空白单元格中的另一张图纸上 例如,表1是总账: 单元格F14包含租金、现金或应收账款等文本 单元格K14包含借方金额。单元格l14包含贷方金额 我想根据F14中的文本,使用下一个可用单元格,将K14或K15中的金额复制并粘贴到第2页的特定范围内 如果是现金,则范围=表2 D1:D10。如果是租赁,则粘贴到范围表2 D20:D30等 任何帮助都将不胜感激。我想这里有一些代码,可以在一定范围内获得下一个可用的免费单元 Sub captu

我是一个使用VBA的初学者

我想将值复制并粘贴到特定范围内第一个空白单元格中的另一张图纸上

例如,表1是总账:

单元格F14包含租金、现金或应收账款等文本

单元格K14包含借方金额。单元格l14包含贷方金额

我想根据F14中的文本,使用下一个可用单元格,将K14或K15中的金额复制并粘贴到第2页的特定范围内

如果是现金,则范围=表2 D1:D10。如果是租赁,则粘贴到范围表2 D20:D30等


任何帮助都将不胜感激。

我想这里有一些代码,可以在一定范围内获得下一个可用的免费单元

Sub capturedata()

Dim sheet1, sheet2 As Worksheet
Dim testValue As String
Dim cashRange, rentRange As Range

Set sheet1 = ActiveWorkbook.Sheets("Sheet1") ' general ledger
Set sheet2 = ActiveWorkbook.Sheets("sheet2")

testValue = sheet1.Range("F14") ' the cell with rent, cash, etc in it

'the ranges
Set cashRange = sheet2.Range("D1:D10")
Set rentRange = sheet2.Range("D20:D30")

Select Case testValue 'based on what is in "f14"
    Case "Rent"
        'paste from k14
        '****I believe the below is the part you're really concerned with***

        For Each cell In cashRange
            If cell.Value = "" Then 'first empty cell
                    cell.Value = sheet1.Range("k14") 'make this more dynamic with a for loop if needed
                Exit For
            End If
        Next cell
    Case "Cash"

        'paste from k15
        For Each cell In rentRange ' make into a function to avoid repeated code
            If cell.Value = "" Then 'first empty cell
                    cell.Value = sheet1.Range("k14")
                Exit For
            End If
        Next cell

    Case "Accounts Receivable"
       'add a for loop here  based on other criteria
    Case Else
    'case not met

End Select


End Sub

请更多地使用标签作为使用技术的方向。您可以随意使用格式选项来提高问题的质量。此外,建议您展示您迄今为止编写的代码,以便人们有一个起点来帮助您。