[英]VBA Concatenate string with previous string value (previous value changes every few cells)
I am working on building data historical of Financial System.我正在构建金融系统的数据历史。
I need a macro that reads if the cell doesn´t contain uppercase, then concatenates the text of this cell with the previous value that was uppercases.我需要一个宏来读取单元格是否不包含大写字母,然后将此单元格的文本与之前的大写值连接起来。
| 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 |
This should do it:这应该这样做:
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
Basically it checks if the cell is uppercase, and if so, sets that as the capitalWord
.基本上它会检查单元格是否为大写,如果是,则将其设置为capitalWord
。 Otherwise, adds the lowercase of that word to the cell value.否则,将该单词的小写添加到单元格值中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.