+ Reply to Thread
Results 1 to 6 of 6

Array - Object required???

Hybrid View

  1. #1
    Buffyslay
    Guest

    Array - Object required???

    i keep getting an error (object required )
    Arr(i, 1).Value = ActiveCell.Value
    Why? where have i gone wrong?
    --------------------------------------------------


    lRowCount = ActiveSheet.UsedRange.Rows.Count
    j = lRowCount - 5 '(as starting from B6)

    ReDim Arr(j, 2)

    Range("B6").Select
    For i = 1 To j
    Arr(i, 1).Value = ActiveCell.Value ********************
    ActiveCell.Offset(0, 1).Select
    Arr(i, 2).Value = ActiveCell.Value
    ActiveCell.Offset(-1, 1).Select
    Next i


    Worksheets("Salaries").Select
    x = lRowCount - 3
    Range("B4").Select
    For m = 3 To x
    ActiveCell.Value = Arr(m, 1).Value
    ActiveCell.Offset(0, 1).Select
    ActiveCell.Value = Arr(m, 2).Value
    ActiveCell.Offset(-1, 1).Select
    Next m


  2. #2
    paul.robinson@it-tallaght.ie
    Guest

    Re: Array - Object required???

    Hi
    did you dim the array at the top of the sub? e.g

    Dim Arr( ) as integer

    Your redim should also be

    ReDim Arr(1 to j, 1 to 2)

    regards
    Paul

    Buffyslay wrote:
    > i keep getting an error (object required )
    > Arr(i, 1).Value = ActiveCell.Value
    > Why? where have i gone wrong?
    > --------------------------------------------------
    >
    >
    > lRowCount = ActiveSheet.UsedRange.Rows.Count
    > j = lRowCount - 5 '(as starting from B6)
    >
    > ReDim Arr(j, 2)
    >
    > Range("B6").Select
    > For i = 1 To j
    > Arr(i, 1).Value = ActiveCell.Value ********************
    > ActiveCell.Offset(0, 1).Select
    > Arr(i, 2).Value = ActiveCell.Value
    > ActiveCell.Offset(-1, 1).Select
    > Next i
    >
    >
    > Worksheets("Salaries").Select
    > x = lRowCount - 3
    > Range("B4").Select
    > For m = 3 To x
    > ActiveCell.Value = Arr(m, 1).Value
    > ActiveCell.Offset(0, 1).Select
    > ActiveCell.Value = Arr(m, 2).Value
    > ActiveCell.Offset(-1, 1).Select
    > Next m



  3. #3
    Buffyslay
    Guest

    Re: Array - Object required???


    paul.robinson@it-tallaght.ie wrote:
    > Hi
    > did you dim the array at the top of the sub? e.g
    >
    > Dim Arr( ) as integer
    >
    > Your redim should also be
    >
    > ReDim Arr(1 to j, 1 to 2)
    >
    > regards
    > Paul


    arh, yes - i knew that the reDim was incorrect...

    if i dim ":as integer" but now getting a new error...
    Compile error: Invalid Qualifier

    if i dim () then i still get the object required


    (full code below
    lots of dims in there - stripping out)


    Sub updateSalaries()

    Dim i, j, k, m As Integer
    Dim c
    Dim strCC, sOut As String

    Dim iFileNum As Integer
    Dim lRowCount As Long
    Dim lRow As Long
    Dim iColCount As Integer
    Dim iCol As Integer
    Dim Arr()


    Worksheets("Salaries").Select

    Sheets("SRD").Select
    Range("B6").Select
    lRowCount = ActiveSheet.UsedRange.Rows.Count
    iColCount = ActiveSheet.UsedRange.Columns.Count


    'Dim aEmpDetails As Variant 'MUST be variant, no brackets
    'aEmpDetails = Range("B6").Resize(lRowCount, 2)
    'Range("B18").Resize(lRowCount, 2) = aEmpDetails
    j = lRowCount - 5


    ReDim Arr(1 To j, 1 To 2)

    Range("B6").Select
    For i = 1 To j
    Arr(i, 1).Value = ActiveCell.Value
    ActiveCell.Offset(0, 1).Select
    Arr(i, 2).Value = ActiveCell.Value
    ActiveCell.Offset(-1, 1).Select
    Next i


    Worksheets("Salaries").Select


    Range("B4").Select
    For m = 3 To lRowCount
    ActiveCell.Value = Arr(m, 1).Value
    ActiveCell.Offset(0, 1).Select
    ActiveCell.Value = Arr(m, 2).Value
    ActiveCell.Offset(-1, 1).Select
    Next m




    End Sub


  4. #4
    paul.robinson@it-tallaght.ie
    Guest

    Re: Array - Object required???

    Hi
    Dim Arr() as integer

    is sensible. I notice a colon in your text - did you type

    Dim Arr(): as integer ??????

    regards
    Paul

    Buffyslay wrote:
    > arh, yes - i knew that the reDim was incorrect...
    >
    > if i dim ":as integer" but now getting a new error...
    > Compile error: Invalid Qualifier
    >



  5. #5
    paul.robinson@it-tallaght.ie
    Guest

    Re: Array - Object required???

    Hi
    I spotted the problem. An array is not an object! you want
    Arr(j, 2) =
    not
    Arr(j,2).Value =

    Paul

    paul.robinson@it-tallaght.ie wrote:
    > Hi
    > Dim Arr() as integer
    >
    > is sensible. I notice a colon in your text - did you type
    >
    > Dim Arr(): as integer ??????
    >
    > regards
    > Paul
    >
    > Buffyslay wrote:
    > > arh, yes - i knew that the reDim was incorrect...
    > >
    > > if i dim ":as integer" but now getting a new error...
    > > Compile error: Invalid Qualifier
    > >



  6. #6
    Buffyslay
    Guest

    Re: Array - Object required???

    thank you to all who looked at this - yes Paul you were right - taking
    out the .Value made it work




    completed code:


    Sub AA_updateSalaries()

    Dim i, j, k, m As Integer
    Dim c
    Dim strCC, sOut As String

    Dim iFileNum As Integer
    Dim lRowCount As Long
    Dim lRow As Long
    Dim iColCount As Integer
    Dim iCol As Integer
    Dim Arr()


    Worksheets("Salaries").Select

    Sheets("SRD").Select
    Range("B6").Select
    lRowCount = ActiveSheet.UsedRange.Rows.Count
    iColCount = ActiveSheet.UsedRange.Columns.Count


    j = lRowCount - 5


    ReDim Arr(1 To j, 1 To 2)

    Range("B6").Select
    For i = 1 To j

    Arr(i, 1) = ActiveCell.Value
    ActiveCell.Offset(0, 1).Select
    Arr(i, 2) = ActiveCell.Value
    ActiveCell.Offset(1, -1).Select
    Next i


    Worksheets("Salaries").Select


    Range("B4").Select
    MsgBox ActiveCell.Address
    For m = 1 To j
    ActiveCell.Value = Arr(m, 1)
    ActiveCell.Offset(0, 1).Select
    ActiveCell.Value = Arr(m, 2)
    ActiveCell.Offset(10, -1).Select
    Next m




    End Sub


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1