简体   繁体   English

VBA到单元格中的粗体数字

[英]VBA to bold numbers within a cell

Weekly I need to perform an activity at work that basically consists on extracting a report, with the activities that will happen on the following week, and format it to the communication template that our company uses. 每周我需要在工作中执行一项活动,该活动主要包括提取报告以及接下来一周将要发生的活动,并将其格式化为公司使用的沟通模板。 As we need to send one communication per site and there are a few of them, I've automated most of the work using macro however there's one last thing to make this spreadsheet work perfectly - as standard on our internal communications, the timings of the activities need to be in bold and that's where I'm stuck. 由于我们需要在每个站点发送一次通信,并且其中有一些通信,因此我已经使用宏自动完成了大部分工作,但是还有最后一件事可以使此电子表格完美运行-作为我们内部通信的标准,活动必须以粗体显示,这就是我要坚持的地方。

I don't know much about programming in VBA but I'm trying a few things, so far I got to bold part of a text within a cell but when it comes to numbers, nothing happens and I don't know exactly why - I'm presuming that's because HH:MM or MM/DD/YYYY are just representative forms of showing a number, for example, 254225 would be 09/02/2010. 我对VBA编程了解不多,但我正在尝试一些事情,到目前为止,我不得不在单元格中加粗文本的一部分,但是当涉及到数字时,什么也没发生,我也不知道为什么-我假设这是因为HH:MM或MM / DD / YYYY只是显示数字的代表形式,例如254225将是09/02/2010。

the cells I'm trying to change come with the following information 我尝试更改的单元格包含以下信息

10/04/2018 15:22 10/04/2018 15:22

and I need them to be 我需要他们成为

10/04/2018 15:22 10/04/2018 15:22

It'd drastically reduce the time taken to perform this activity - from 2 hours to around 30 minutes. 它将大大减少执行此活动所需的时间-从2小时减少到30分钟左右。

Really appreciate all the replies, thank you in advance. 真的感谢所有答复,在此先感谢您。

I don't know of any method to format only the time bold if a number/date format like MM/DD/YYYY HH:MM is used. 如果使用数字/日期格式(例如MM/DD/YYYY HH:MM ),我不知道有什么方法可以仅格式化时间粗体。 I'm pretty sure that this is only possible with text. 我很确定这仅适用于文本。

So I recommend to split date and time in 2 different columns: 因此,我建议将日期和时间分为2个不同的列:

Therfore duplicate eg the date of column A with the formula =A:A into column B and then format the columns 因此,例如将公式=A:A列日期复制到B列中,然后格式化这些列

A                   B
10/04/2018 15:22    =A:A
  1. Number format column A MM/DD/YYYY so it only shows the date part. 数字格式列A MM/DD/YYYY因此仅显示日期部分。
  2. Number format column B HH:MM so it only shows the time part. 数字格式B列HH:MM因此仅显示时间部分。
  3. Format column B as bold. 将列B设置为粗体。

So the result would be 所以结果是

A                   B
10/04/2018          15:22

in 2 different columns (where column B is bold). 在2个不同的列中(其中B列为粗体)。

Say we have real date/times in column A like: 假设我们在A列中有真实的日期/时间,例如:

10/10/2018 23:30
10/31/2018 06:30
09/26/2018 20:44
11/17/2018 07:11
10/13/2018 16:16
09/20/2018 13:26
10/08/2018 01:06
11/10/2018 14:33
10/16/2018 11:28
11/16/2018 11:53
10/20/2018 08:51
11/23/2018 04:25
10/21/2018 12:41
10/29/2018 14:35
10/14/2018 16:09
11/15/2018 11:56
11/20/2018 10:16
09/21/2018 22:45
10/21/2018 17:55
10/21/2018 19:29

running this simple macro will: 运行这个简单的宏将:

  • convert them to text 将它们转换为文本
  • enbolden the time-part 充实时间


Sub marine()
    Dim rng As Range, r As Range
    Set rng = Intersect(Columns(1), ActiveSheet.UsedRange)
    For Each r In rng
        r.Value = "'" & r.Text
        r.Characters(12, 5).Font.Bold = True
    Next r
End Sub

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM