0

ユーザーが入力したさまざまな文字列を連結して、ユーザーが提供した属性に基づく他の Active Directory ユーザー属性の他のセルを埋めるマクロがあります。

Option Explicit

Sub SubStringConcatenate()

'variables
Dim strFirstName As String
Dim strSurName As String
Dim strDomain As String
Dim strOU As String
Dim strChildOU As String

Dim intRowCount As Integer

Dim rngLastRow As Range

Set rngLastRow = Worksheets("NewADUserAttribs").Cells.End(xlUp)

'set first row to be processed
intRowCount = 2

'loop until all used rows have been processed
For Each rngLastRow In Sheets("NewADUserAttribs").UsedRange.Rows.Count

'define name variables
strFirstName = Cells(intRowCount, 1).Value
strSurName = Cells(intRowCount, 2).Value

'define initials cell location and concatenate
Cells(intRowCount, 3).Value = Left(strFirstName, 1) & Left(strSurName, 1)

' define fullname cell location and concatenate
Cells(intRowCount, 4).Value = strFirstName & " " & strSurName

'define SAM cell location and concatenate
Cells(intRowCount, 5).Value = Left(strFirstName, 2) & Left(strSurName, 4)

'define domain string variable and logon range and concatenate
Cells(intRowCount, 7).Value = strFirstName & "." & strSurName

'add 1 to row count to prepare for next row in table
intRowCount = intRowCount + 1

Next

End Sub

デバッグしてもエラーはありません。しかし、マクロを実行しようとすると、オブジェクトが必要なエラーが発生し、コード内のどこにあるかがわかりません。for each ステートメントのどこかにあると思います。エクセル2010を使用しています。

4

1 に答える 1

4
For Each rngLastRow In Sheets("NewADUserAttribs").UsedRange.Rows.Count 

する必要があります

For Each rngLastRow In Sheets("NewADUserAttribs").UsedRange.Rows

rngLastRowしかし、ループ内で使用していません。あなたはそれを(例えば)次のように使うことができます:

rngLastRow.Cells(3).Value = Left(strFirstName, 1) & Left(strSurName, 1)
于 2012-09-04T19:32:10.483 に答える