Excel 加上「;从头开始,然后;到每个单元格数据的末尾

Excel 加上「;从头开始,然后;到每个单元格数据的末尾,excel,Excel,我有一个相当大的Excel csv文件,需要在每个单元格的开头和结尾添加“和” 单元格中包含混合文本,无论是否为 数字 正文 链接 等等,我需要在每个单元格的开头和结尾加上引号 我怎样才能做到这一点?手工: 将第一个单元格值更改为=“”&A1&“” 将此单元格格式拖到整页 或者通过vb宏我从 它使用不同的数组来提高速度效率,只更新电子表格的UsedRange部分 同时按Alt和F11以转到VBE 插入模块 复制并粘贴下面的代码 同时按Alt和F11返回Excel(&F) 从“开发人员”

我有一个相当大的Excel csv文件,需要在每个单元格的开头和结尾添加

单元格中包含混合文本,无论是否为

  • 数字
  • 正文
  • 链接
等等,我需要在每个单元格的开头和结尾加上引号

我怎样才能做到这一点?

手工:

  • 将第一个单元格值更改为
    =“”&A1&“”
  • 将此单元格格式拖到整页

或者通过vb宏

我从

它使用不同的数组来提高速度效率,只更新电子表格的
UsedRange
部分

  • 同时按Alt和F11以转到VBE
  • 插入模块
  • 复制并粘贴下面的代码
  • 同时按Alt和F11返回Excel(&F)
  • 从“开发人员”选项卡运行宏
如果您愿意,可以将其调整为忽略空白单元格-请告诉我

Sub AddStrings()
Dim rng1 As Range
Dim rngArea As Range
Dim strRep1 As String
Dim strRep2 As String
Dim lngRow As Long
Dim lngCol As Long
Dim lngCalc As Long
Dim X()


strRep1 = """"
strRep2 = """"

ActiveSheet.UsedRange
Set rng1 = ActiveSheet.UsedRange

'Speed up the code by turning off screenupdating and setting calculation to manual
'Disable any code events that may occur when writing to cells
With Application
    lngCalc = .Calculation
    .ScreenUpdating = False
    .Calculation = xlCalculationManual
    .EnableEvents = False
End With

'Test each area in the user selected range

'Non contiguous range areas are common when using SpecialCells to define specific cell types to work on
For Each rngArea In rng1.Areas
    'The most common outcome is used for the True outcome to optimise code speed
    If rngArea.Cells.Count > 1 Then
        'If there is more than once cell then set the variant array to the dimensions of the range area
        'Using Value2 provides a useful speed improvement over Value. On my testing it was 2% on blank cells, up to 10% on non-blanks
        X = rngArea.Value2
        For lngRow = 1 To rngArea.Rows.Count
            For lngCol = 1 To rngArea.Columns.Count
                'replace the leading zeroes
                X(lngRow, lngCol) = strRep1 & X(lngRow, lngCol) & strRep2
            Next lngCol
        Next lngRow
        'Dump the updated array sans leading zeroes back over the initial range
        rngArea.Value2 = X
    Else
        'caters for a single cell range area. No variant array required
        rngArea.Value = strRep1 & rngArea.Value2 & strRep2
    End If
Next rngArea

'cleanup the Application settings
With Application
    .ScreenUpdating = True
    .Calculation = lngCalc
    .EnableEvents = True
End With

End Sub