问问题
158 次
1 回答
0
我不太确定这是否是您想要实现的目标,但据我了解,这里有一个小片段应该可以解决问题。
'Define your grid area
firstRowOfGrid = 17
lastRowOfGrid = 29
numberOfCols = 4
firstColLetter = "B"
cellValue = "" 'This one will hold the cell value
concatenatedString = "" 'This will be the concatenated string
firstColLetter = Asc(firstColLetter) 'Convert the letter to a number
For j = firstColLetter To firstColLetter + numberOfCols 'Loop through the columns
For i = firstRowOfGrid To lastRowOfGrid 'Loop through the rows
cellValue = Range(Chr(j) & i).Value 'Get the current cell value
If (cellValue) Then 'Check if current cell has a value
'The new value of the concatenated string is the concatenated string itself followed by a semi-colon and the current
'cell value
concatenatedString = concatenatedString & ";" & cellValue
End If
Next i
Next j
'Remove the first semi-colon
concatenatedString = Mid(concatenatedString, 2, Len(concatenatedString))
'Do something with your string (currently displaying in a msgbox)
MsgBox concatenatedString
此代码将遍历字段 B17 到 E29,并将单元格值(如果单元格不为空)添加到您以后可以使用的串联字符串中。
于 2013-05-15T14:23:02.010 回答