excel VB 使用例子
1、拼接 sql 语句
Sub geSql2() Dim i, j As Integer Dim str As String For i = 2 To 4591 Range("AA" & i) = "INSERT INTO `t_idx_dim`(`index_id`, `index_name`, `index_name_en`, `........`) VALUES " str = "" '从A循环到X,将 Ai~Xi单元格内容进行拼接 For j = Asc("A") To Asc("X") str = str & Range(Chr(j) & i) If j <> Asc("X") Then str = str & "','" End If Next Range("AA" & i) = Range("AA" & i) & "('" & str & "');" Next End Sub