更改数字中最后3位数字的字体颜色

时间:2018-08-15 14:54:11

标签: excel vba excel-vba complete

我在Excel VBA中遇到了一些代码问题。抱歉,这真的很简单,我是初学者!

我有一个始终为7位数字的标识号,它位于B列中。我需要使用ID号的后3位数字并更改字体颜色。

我尝试使用Right()函数,但无法弄清楚如何将其与Font.Color函数结合使用。

Sub Test    

Dim i As Long

For i = 1 To 3
    RResult = Right(ActiveCell, 3)
    LResult = Left(ActiveCell, 4)
    ActiveCell = LResult + " " + RResult
    ActiveCell.Offset(1, 0).Select
Next i

End Sub

我尝试使用上面的代码分隔数字,但是我无法更改RResult(正确结果)变量的字体颜色。

请帮助!谢谢!

编辑:谢谢您的帮助!

2 个答案:

答案 0 :(得分:0)

尝试以下操作:

CREATE VIEW [dbo].[View_1]
(column_name)
AS
    SELECT colA, colB, json_query(infoJson) AS Expr1
      FROM dbo.Table_1 
       FOR json auto

答案 1 :(得分:0)

此方法为您提供了更多选择:

您将范围参考以及可选的字符计数和RGB颜色传递给它。

'Colour the last three characters in the ActiveCell to red.
Sub Test()
    ColourLastThree ActiveCell
End Sub

'Colour last four characters in Sheet1!A1 to red.
Sub Test1()
    ColourLastThree Worksheets("Sheet1").Range("A1"), 4
End Sub

'Colour last four characters in Sheet1!A1 to Green.
Sub Test2()
    ColourLastThree Worksheets("Sheet1").Range("A3"), 4, RGB(0, 255, 0) 'or can use 65535 as RGB.
End Sub

'Colour last three character in each cell on the ActiveSheet in A1:A4.
Sub Test3()
    ColourLastThree Range("A1:A4")
End Sub

然后您可以调用该过程:

relation[name="Becva"][waterway=river]-> .firstRiver;
foreach .firstRiver -> .fr
(

  //works:
  relation[name=Morava]-> .nextRiver;

  //works:
  make debug enters = fr.u(t["destination"]); out  ;
  //output:
  //<debug id="1">
  //  <tag k="enters" v="Morava"/>
  //</debug>

  //
  // how would that work??  <====================================
  //
  //relation[name=fr.u(t["destination"])]-> .nextRiver;
  //
  //An error occured during the execution of the overpass query!
  //This is what overpass API returned:
  //Error: line 8: parse error: ']' expected - '.' found.
  //Error: line 8: parse error: ';' expected - ')' found.

);
.firstRiver out geom;
.nextRiver out geom;

编辑:我已经更新了代码,以循环遍历传递的Target范围内的每个单元格(如Test3过程所示)。