如果我尝试添加另一个代码,我的代码只会让我选择22列然后会出现“太多行继续”。
我要为这个公式添加大约100列,并且需要复制另外100个不需要“检查”的列。
代码
strSQL = "SELECT a.[A], " _ & "(SELECT Max([Serial]) FROM [Data$] b WHERE b.[A]=a.A) As Serial, " _
& "(SELECT Max([B]) FROM [Data$] b WHERE b.[A]=a.A) As B, " _
& "(SELECT Max([C]) FROM [Data$] b WHERE b.[A]=a.A) As C, " _
& "(SELECT Max([D]) FROM [Data$] b WHERE b.[A]=a.A ) As D, " _
& "(SELECT Max([E]) FROM [Data$] b WHERE b.[A]=a.A ) As E, " _
& "(SELECT Max([F]) FROM [Data$] b WHERE b.[A]=a.A ) As F, " _
& "(SELECT Max([G]) FROM [Data$] b WHERE b.[A]=a.A ) As G, " _
& "(SELECT Max([H]) FROM [Data$] b WHERE b.[A]=a.A ) As H, " _
& "(SELECT Max([I]) FROM [Data$] b WHERE b.[A]=a.A ) As I, " _
& "(SELECT Max([J]) FROM [Data$] b WHERE b.[A]=a.A ) As J, " _
& "(SELECT Max([K]) FROM [Data$] b WHERE b.[A]=a.A ) As K, " _
& "(SELECT Max([L]) FROM [Data$] b WHERE b.[A]=a.A ) As L, " _
& "(SELECT Max([M]) FROM [Data$] b WHERE b.[A]=a.A ) As M, " _
& "(SELECT Max([N]) FROM [Data$] b WHERE b.[A]=a.A ) As N, " _
& "(SELECT Max([O]) FROM [Data$] b WHERE b.[A]=a.A ) As O, " _
& "(SELECT Max([P]) FROM [Data$] b WHERE b.[A]=a.A ) As P, " _
& "(SELECT Max([Q]) FROM [Data$] b WHERE b.[A]=a.A ) As Q, " _
& "(SELECT Max([R]) FROM [Data$] b WHERE b.[A]=a.A ) As R, " _
& "(SELECT Max([S]) FROM [Data$] b WHERE b.[A]=a.A ) As S, " _
& "(SELECT Max([T]) FROM [Data$] b WHERE b.[A]=a.A ) As T, " _
& "(SELECT Max([U]) FROM [Data$] b WHERE b.[A]=a.A ) As U, " _
& "(SELECT Max([V]) FROM [Data$] b WHERE b.[A]=a.A ) As V " _
& "FROM [Data$] a " _
& "GROUP BY a.[A]"
答案 0 :(得分:4)
或发表声明
strSql = "bla bla"
strSql = strSql & "bla bla 2"
strSql = strSql & "bla bla 3"
strSql = strSql & "bla bla 4"
...
strSql = strSql & "bla bla n"
这将使其可读并且不会跨越许多文本列。
答案 1 :(得分:0)
嗯,只需减少线条,每条线条更长一点......
strSQL = "SELECT a.[A], " _ & "(SELECT Max([Serial]) FROM [Data$] b WHERE b.[A]=a.A) As Serial, " _
& "(SELECT Max([B]) FROM [Data$] b WHERE b.[A]=a.A) As B, (SELECT Max([C]) FROM [Data$] b WHERE b.[A]=a.A) As C, (SELECT Max([D]) FROM [Data$] b WHERE b.[A]=a.A ) As D, " _
& "(SELECT Max([E]) FROM [Data$] b WHERE b.[A]=a.A ) As E, (SELECT Max([F]) FROM [Data$] b WHERE b.[A]=a.A ) As F, (SELECT Max([G]) FROM [Data$] b WHERE b.[A]=a.A ) As G, " _
& "(SELECT Max([H]) FROM [Data$] b WHERE b.[A]=a.A ) As H, (SELECT Max([I]) FROM [Data$] b WHERE b.[A]=a.A ) As I, (SELECT Max([J]) FROM [Data$] b WHERE b.[A]=a.A ) As J, " _
& "(SELECT Max([K]) FROM [Data$] b WHERE b.[A]=a.A ) As K, (SELECT Max([L]) FROM [Data$] b WHERE b.[A]=a.A ) As L, (SELECT Max([M]) FROM [Data$] b WHERE b.[A]=a.A ) As M, " _
& "(SELECT Max([N]) FROM [Data$] b WHERE b.[A]=a.A ) As N, (SELECT Max([O]) FROM [Data$] b WHERE b.[A]=a.A ) As O, (SELECT Max([P]) FROM [Data$] b WHERE b.[A]=a.A ) As P, " _
& "(SELECT Max([Q]) FROM [Data$] b WHERE b.[A]=a.A ) As Q, (SELECT Max([R]) FROM [Data$] b WHERE b.[A]=a.A ) As R, (SELECT Max([S]) FROM [Data$] b WHERE b.[A]=a.A ) As S, " _
& "(SELECT Max([T]) FROM [Data$] b WHERE b.[A]=a.A ) As T, (SELECT Max([U]) FROM [Data$] b WHERE b.[A]=a.A ) As U, (SELECT Max([V]) FROM [Data$] b WHERE b.[A]=a.A ) As V " _
& "FROM [Data$] a " _
& "GROUP BY a.[A]"