-1

私は過去数週間、Excel vb を学んでいるので、常にスタック オーバー フローを検索してきましたが、最終的に困惑しました。

x 位置の変数と y 位置の変数を使用して、セルをアクティブにする必要があります。

xval は整数です yval は文字列です

私は運が悪いので、これを行うために一致機能を使用しようとしています。

これが私が試したことです。

Sheets("Attributes").Select      'this is the sheet with the raw data
Range("C2").Activate
Dim xval As String                'this is the row I'm looking for
Dim yval As Integer               'this is the colum I'm looking for
Dim value As String               'when I find the exact right cell on the next sheet this is the value that needs to go in it.

' start loop here

xval = ActiveCell.Offset(0, -2)   'populate variables
yval = ActiveCell
value = ActiveCell.Offset(0, 2)
Sheets("output").Select              'switch to output sheet
Range("A1").Activate

Cells(WorksheetFunction.Match(xval, "A:A", 0), WorksheetFunction.Match(yval, "A1:A500", 0)).Activate    'this line doesn't work


ActiveCell = value

'end loop when data runs out using is empty function
4

1 に答える 1

0
Sub Tester()

    Dim xval As String
    Dim yval As Integer
    Dim v As String
    Dim shtOut As Worksheet
    Dim f As Range

    Set shtOut = ThisWorkbook.Sheets("output")

    With ThisWorkbook.Sheets("Attributes").Range("C2")
        xval = .Offset(0, -2).value
        yval = .value
        v = .Offset(0, 2).value
    End With

    On Error Resume Next
    Set f = shtOut.Cells(WorksheetFunction.Match(xval, shtOut.Range("A:A"), 0), _
                      WorksheetFunction.Match(yval, shtOut.Range("A1:A500"), 0))
    On Error GoTo 0

    If Not f Is Nothing Then f.value = v

    'flag if not found
    ThisWorkbook.Sheets("Attributes").Range("C2").Font.Color = _
                               IIf(f Is Nothing, vbRed, vbGreen)


End Sub
于 2013-05-23T17:07:41.873 に答える