我正在尝试根据 A 列中的值填充工作表上的 C 列值。因此,如果 A 列值为 1,那么我希望 C 列中相应单元格中的值为 10,否则什么都不做。< /p>
$NestedGroupUsers = Get-ADUsers_cachedV2 -GroupName $nestedmember.distinguishedName
$table2 = $NestedGroupUsers | Add-Member -NotePropertyName MainParentGroup -NotePropertyValue $groupNestedName -PassThru -Force
$AddedMainGroupTable = MainGroupChoice -InputObject $table2 -choice1 $adgroupname.name -Choice2 $groupNestedName -Value1 $table2.MainParentGroup -Value2 $table2.ParentGroup
function MainGroupChoice {
param (
[Parameter(ValueFromPipeline)]$InputObject,
[Parameter(ValuefromPipelineByPropertyName = $true)] $Value1,
[Parameter(ValuefromPipelineByPropertyName = $true)] $Value2,
[Parameter(ValuefromPipelineByPropertyName = $true)][String] $Choice1,
[Parameter(ValuefromPipelineByPropertyName = $true)][String] $Choice2
)
process {
# value1 = table2.parentGroup ,
# value2 = table2.parentGroup
# choice1 = adgroupname,
#choice2 nestedmember,distinguishedname
if ($Value1 -eq $Value2 ) {
return $InputObject |Add-Member -NotePropertyName MainGroup -NotePropertyValue $choice1 -PassThru -Force
}
else {
return $InputObject |Add-Member -NotePropertyName MainGroup -NotePropertyValue $Choice2 -PassThru -Force
}
}
}
如果有任何帮助,请向我展示更好的方法,我将不胜感激。 谢谢
答案 0 :(得分:0)
试试下面的子。
Sub test()
Dim sh As Worksheet
Dim cel As Range
Dim LastRow As Long
Set sh = ThisWorkbook.Worksheets("Report")
LastRow = sh.Cells(sh.Rows.Count, 1).End(xlUp).Row
For Each cel In sh.Range("A9:A" & LastRow)
If cel.Value = 1 Then
cel.Offset(0, 2).Value = 10
End If
Next cel
Set sh = Nothing
End Sub