'将选定的单元格区域里面的单元格的值拼接到一起,使用spliter分隔,默认使用逗号分隔
'mRange:单元格区域
'spliter:拼接两个单元格时的分隔字符串
Function joincell(mRange As Range, spliter As String)
Dim cells, result
If Len(spliter) < 1 Then
spliter = ","
End If
cells = mRange.cells
For r = 1 To mRange.Rows.Count
For c = 1 To mRange.Columns.Count
result = result & spliter & cells(r, c)
Next
Next
joincell = result
End Function
生成列名
=MID(joincell(A3:H3,","),2,1000)
生成插入数据的sql
="insert into safety_evaluation_method ("&$I$3&") values(UUID(),"&SUBSTITUTE(MID(joincell(B4:H4,"','")&"'",3,1000),"''","null")&");"
="insert into safety_evaluation_method ("&$I$3&") values("&SUBSTITUTE(MID(joincell(A4:H4,"','")&"'",3,1000),"''","null")&");"