今天我花了很长时间查找一种在指定范围内交替行颜色的方法.那里真的不是很多,说实话,我发现看起来过于复杂.所以,我决定停止表现得像一个无耻的'script-kiddy'并将下面的样本放在一起:
Sub AlternateRowColors()
Dim lastRow as Long
lastRow = Range("A1").End(xlDown).Row
For Each Cell In Range("A1:A" & lastRow) ''change range accordingly
If Cell.Row Mod 2 = 1 Then ''highlights row 2,4,6 etc|= 0 highlights 1,3,5
Cell.Interior.ColorIndex = 15 ''color to preference
Else
Cell.Interior.ColorIndex = xlNone ''color to preference or remove
End If
Next Cell
End Sub
Run Code Online (Sandbox Code Playgroud)
现在我知道这有效,但我想知道是否有更简单的方法?
如果是这样,请告诉我,因为我非常渴望学习简化,因为我现在倾向于编写详细的代码.如果没有,那么这个条目是否可以找到谷歌第1页的搜索条件,因为我花了很长时间才找到任何有用的东西.
留给脚本小子的好处的评论.
如果您的数据不包含任何预先存在的颜色,则可能会删除以下代码行:
Else
Cell.Interior.ColorIndex = xlNone
Run Code Online (Sandbox Code Playgroud) 我有一个要求,需要将文件中的 JSON 对象与进入 Anypoint MQ 队列的 JSON 消息进行比较。我能够从队列中获取消息。我使用了下面的脚本,但它不起作用。我都做了-eq
,Compare-Object
但它们不起作用。
$po_ps_output = $filemessagecontent | ConvertFrom-Json
$po_python_output = $mqmessagecontent.body | ConvertFrom-Json
$result = $po_ps_output -eq $po_python_output
Run Code Online (Sandbox Code Playgroud) 我在 Azure PowerShell 中遇到了问题。我无法连接到 AzureRM 帐户。它显示此错误:
Connect-AzureRMAccount :术语“Connect-AzureRMAccount”不被识别为 cmdlet、函数、脚本文件或可运行程序的名称。检查名称的拼写,或者如果包含路径,请验证路径是否正确,然后重试。在 line:1 char:1 + Connect-AzureRMAccount + ~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (Connect-AzureRMAccount:String) [], CommandNotFoundException + FullQualifiedErrorId : CommandNotFoundException
我在 Mac OS 中这样做。首先,我使用以下命令安装了 PowerShell:brew cask install PowerShell。然后我做了以下事情:
我期待第 5 步会弹出登录窗口。请帮忙
我正在尝试编写一个脚本来分别显示用户特定的属性、名称、邮件地址、OU。输出符合预期,但是我找不到任何解决方案来仅提取和显示用户的 OU 详细信息。当我选择“DistinguishedName”时,响应如下模式:{CN = X, OU = Y, DC = Z},我只想显示 OU。iv'e 试图找到一种方法来分割 DN 字符串,但到目前为止还没有什么乐趣。
提前致谢
Set-ExecutionPolicy Unrestricted
$filepath = "C:\Users\Administrator\Desktop\ADusers.Csv"
$searchDomain = "DC = GSDOM, DC=internal"
$adminCredential = Get-Credential
$adSrv = 'GSDC'
$session = New-PSSession -ComputerName "$adSrv" -Credential ($adminCredential)
Invoke-Command $session -Scriptblock { Import-Module ActiveDirectory }
Import-PSSession -Session $session -module ActiveDirectory
Get-ADUser -Filter * -Properties * | Select-Object "Name", "EmailAddress", "distinguishedName"
Run Code Online (Sandbox Code Playgroud)