0

我是一个真正的新手,一直在这里寻求帮助,但找不到我想要的。

我创建了一个将数据填充到目标工作表中的用户表单,我需要它对每一行数据进行顺序编号,并确保每次传输数据时它都会从中断处继续编号。

我不知道从哪里开始。

4

1 回答 1

0

我希望我正确地理解了你。这是宏的作用。

在此处输入图像描述

当您尝试时,请记住对代码的配置区域进行更改。

Sub NumberSequence()

Dim input_one As String, input_two As String, input_three As String
Dim target As String, main As String, col_start As String
Dim col_start_number As Long, substract As Long
Dim next_row As Long, next_number As Long

'CONFIG HERE
'---------------------------------------
'ranges of form inputs
input_one = "B3"
input_two = "C3"
input_three = "D3"

'first column where data starts in target sheet
col_start = "A"

'from what row do you want to start counting?
substract = 3

'names of sheets
target = "target"
main = "form"
'---------------------------------------

'convert the letter of the column to a number
col_start_number = Range(col_start & 1).Column

'get next empty row in target sheet
next_row = _
Sheets(target).Cells(Rows.Count, col_start_number).End(xlUp).row + 1

'next number in the sequence
next_number = next_row - substract + 1

With Sheets(target)
    
    'transfer the sequencial number
    .Cells(next_row, col_start_number) = next_number
    
    'transfer the inputs of the form
    .Cells(next_row, col_start_number + 1) = _
    Sheets(main).Range(input_one)

    .Cells(next_row, col_start_number + 2) = _
    Sheets(main).Range(input_two)
    
    .Cells(next_row, col_start_number + 3) = _
    Sheets(main).Range(input_three)

End With

End Sub
于 2021-02-03T21:49:22.753 回答