Excel、VBA、使用偏移量添加到变量字符串的问题

Excel、VBA、使用偏移量添加到变量字符串的问题,excel,vba,string,Excel,Vba,String,提前谢谢 我遇到了一个问题,我确信它很容易解决,但我似乎看不出我哪里出了问题。 这段代码的思想是在表单上运行检查,以确保在将其添加到数据库之前填写了所有字段: Dim aSCt As Integer, blankchk As Range, eRmSg As String, DISP As Integer, SectDisp As Integer eRmSg = "Please ensure that all assesments have been completed and where not

提前谢谢

我遇到了一个问题,我确信它很容易解决,但我似乎看不出我哪里出了问题。 这段代码的思想是在表单上运行检查,以确保在将其添加到数据库之前填写了所有字段:

Dim aSCt As Integer, blankchk As Range, eRmSg As String, DISP As Integer, SectDisp As Integer
eRmSg = "Please ensure that all assesments have been completed and where not applicable the N/A option is selected." & vbNewLine & "The following fields need to be filled in:" & vbNewLine & vbNewLine
aSCt = 0
DISP = 0
SectDisp = 0
Set blankchk = Range("H9")
        Do While aSCt < 14
            If IsEmpty(blankchk) Then
                'if first blank in this section then add section title
                If SectDisp = 0 Then
                    eRmSg = eRmSg & "SECTION A - scope:" & vbNewLine
                    SectDisp = 1
                End If
                'add area to list
                eRmSg = eRmSg & "    " & blankchk.Offset(0, -6).Value & vbNewLine
                'Tell error message to display at end
                DISP = 1
            End If
            'choose next cell down and update counter
            blankchk = blankchk.Offset(1, 0)
            aSCt = aSCt + 1
        Loop
Dim aSCt为整数,blankchk为范围,eRmSg为字符串,DISP为整数,SectDisp为整数
eRmSg=“请确保所有评估都已完成,并且在不适用的情况下选择了N/A选项。”&vbNewLine&“需要填写以下字段:”&vbNewLine&vbNewLine
aSCt=0
DISP=0
isp=0
设置blankchk=范围(“H9”)
当aSCt<14时执行此操作
如果我是空的(blankchk),那么
'如果此节中的第一个为空,则添加节标题
如果isp=0,则
eRmSg=eRmSg&“A节-范围:”&vbNewLine
SectDisp=1
如果结束
'将区域添加到列表中
eRmSg=eRmSg&“”和blankchk.Offset(0,-6).Value和vbNewLine
'告诉要在末尾显示的错误消息
DISP=1
如果结束
'选择下一个单元格并更新计数器
blankchk=blankchk.偏移量(1,0)
aSCt=aSCt+1
环
我觉得这很好。。但是,我在向字符串添加“blankchk.Offset(0,-6).Value”时遇到了一个问题。出于某种原因,它每次都取范围(“H9”).值(原始“blankchk”名称)。因此,输出将显示:

A节-范围
钻机名称
钻机名称
钻机名称
钻机名称
钻机名称
钻机名称
钻机名称
钻机名称
钻机名称
钻机名称

等等

为什么要这样做?偏移量(1,0)肯定会改变这个参考

请帮助

只需更改

blankchk = blankchk.Offset(1, 0)


:)

忘了为此感谢你了。干得不错,我打了个盹哈哈
Set blankchk = blankchk.Offset(1, 0)