VBA将字符串与先前的字符串值连接在一起(先前的值每隔几个单元格更改一次)

问题描述 投票:0回答:1

我正在构建金融系统的历史数据。

我需要一个宏,该宏读取单元格中是否包含大写字母,然后将该单元格的文本与之前的大写字母值连接起来。

|    FIRST STEP    |
|------------------|
|     |    Name    |
| --- | ---------- |
|  1  |DISPONIBLE: | 
|  2  |Caja        |
|  3  |Bancos      |
|  4  |INVERSIONES:|
|  5  |Temporales  |
|  6  |Largoplazo  |
|  7  |CARTERA:    |
|  8  |Crédito     |
|     |    LAST STEP         |
|----------------------------|
|     |    Name              |
| --- | -------------------- |
|  1  |DISPONIBLE:           | 
|  2  |disponibleCaja        |
|  3  |disponibleBancos      |
|  4  |INVERSIONES:          |
|  5  |inversionesTemporales |
|  6  |inversionesLargoplazo |
|  7  |CARTERA:              |
|  8  |carteraCrédito        |
arrays vba string uppercase
1个回答
0
投票

这应该做:

Sub t()
Dim rng As Range, cel As Range
Dim capitalWord As String
Set rng = Range("A1:A8") 'Adjust as needed
For Each cel In rng
    If IsUppercase(cel.Value) Then
        capitalWord = Replace(cel.Value, ":", "")
    Else
        cel.Value = LCase(capitalWord) & WorksheetFunction.Proper(cel.Value)
    End If
Next cel
End Sub
Public Function IsUppercase(AString As String) As Boolean
  IsUppercase = (UCase(AString) = AString)
End Function

基本上检查单元格是否为大写,如果是,则将其设置为capitalWord。否则,将该单词的小写字母添加到单元格值中。

© www.soinside.com 2019 - 2024. All rights reserved.