VBA Excel-将大小写更改为适当的大小写 [英] VBA Excel - changing case to Proper Case

查看:91
本文介绍了VBA Excel-将大小写更改为适当的大小写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Stackoverflow的新手,所以希望我可以在正确的位置发布此问题.

I'm new to Stackoverflow so hopefully I have posted this question in the right place.

我无法让我的代码在VBA中工作.我希望它选择D:F列,直到最后一个单元格值为止.通过此选择,我想将单元格的大小写(当前为大写)更改为适当大小写.

I'm having trouble getting my code to work in VBA. I want it to select columns D:F until the last cell value. With this selection, I would like to change the case of the cells (they are currently uppercase) to Proper case.

Dim Lastrow As Integer
Dim range As Variant

With Worksheets("Overdue PO")
    Lastrow = .Cells(Rows.Count, "D").End(xlUp).Row
    .range("D2:F" & Lastrow).Select
    range = Selection.Value
End With

Application.Proper (range)

当前它选择直到最底行的范围,但不会更改文本的大小写.运行代码时没有错误.

It currently selects the range until the bottom row, but it doesn't change the case of text. No error appears when running the code.

先谢谢您了:)

推荐答案

尝试一下

Sub test()

Dim Lastrow As Integer
Dim range As range
Dim c As range


With Worksheets("Overdue PO")
Lastrow = Columns("D:F").Cells.Find(What:="*", LookIn:=xlValues,   SearchOrder:=xlByColumns, SearchDirection:=xlPrevious).Row
    .range("D2:F" & Lastrow).Select
    Set range = Selection
End With

For Each c In range
    c.Value = Application.WorksheetFunction.Proper(c.Value)
Next c


End Sub

这篇关于VBA Excel-将大小写更改为适当的大小写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆