Consulting

Results 1 to 5 of 5

Thread: Dim problem

  1. #1
    VBAX Contributor
    Joined
    Jul 2017
    Location
    Zurich
    Posts
    132
    Location

    Dim problem

    Hi Forum

    got a weird problem...my routine worked perfectly for quite a while, but suddenly it tells me that there's a problem with my dimensions...(the one marked up in red)
    I just can't find a typo or something wrong with it...anybody see something wrong?

    'Worksheets dim Dim wsTeilnehmer As Worksheet: Set wsTeilnehmer = A01
    Dim wsMatrix As Worksheet: Set wsMatrix = A02
    Dim wsHelper As Worksheet: Set wsHelper = A99

    'Rows dim
    Dim lrMatrix As Long: lrMatrix = wsMatrix.Cells(Rows.count, 2).End(xlUp).Row
    Dim lrTeilnehmer As Long: lrTeilnehmer = wsTeilnehmer.Cells(Rows.count, 2).End(xlUp).Row
    Dim lrHelperMatrix As Long: lrHelperMatrix = wsHelper.Cells(Rows.count, 1).End(xlUp).Row
    Dim lrHelperMatrixFehler As Long: lrHelperMatrixFehler = wsHelper.Cells(Rows.count, 6).End(xlUp).Row

    'Columns dim
    Dim lcMatrix As Long: lcMatrix = wsMatrix.Cells(3, Columns.count).End(xlToLeft).Column

    'Anzahl dim
    Dim numMitarbeiter As Long: numMitarbeiter = lrMatrix - 5
    Dim numTeilnehmer As Long: numTeilnehmer = lrTeilnehmer - 3
    Dim numHelperMatrix As Long: numHelperMatrix = lrHelperMatrix - 1

    'Ranges dim
    Dim rngLuNrMatrix As Range: Set rngLuNrMatrix = wsMatrix.Range("B6:B" & lrMatrix)
    Dim rngTrainingNrMatrix As Range: Set rngTrainingNrMatrix = wsMatrix.Range(Cells(3, 1), Cells(3, lcMatrix))
    Dim rngLuNrTeilnehmer As Range: Set rngLuNrTeilnehmer = wsTeilnehmer.Range("N4:N" & lrTeilnehmer)
    Dim rngTraining As Range: Set rngTraining = wsTeilnehmer.Range("K4:K" & lrTeilnehmer)
    Dim rngDatum As Range: Set rngDatum = wsTeilnehmer.Range("B4:B" & lrTeilnehmer)
    Dim rngStufe As Range: Set rngStufe = wsTeilnehmer.Range("M4:M" & lrTeilnehmer)

  2. #2
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    Works: Range("B6:B" & lrMatrix)
    Fails: Range(Cells(3, 1), Cells(3, lcMatrix))

    What about Range("A3").Resize(1, lcMatrix)
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  3. #3
    VBAX Regular
    Joined
    Jan 2018
    Posts
    55
    Location
    Hello, nikki333.
    You need to modify your code like this:

    Set rngTrainingNrMatrix = wsMatrix.Range(wsMatrix.Cells(3, 1), wsMatrix.Cells(3, lcMatrix))
    When you use worksheet specified Range, each Cells property also needs to be worksheet specified.
    Last edited by yujin; 01-27-2018 at 05:05 PM.

  4. #4
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,727
    Location
    Try

    Set rngTrainingNrMatrix = Range(wsMatrix.Cells(3, 1), wsMatrix.Cells(3, lcMatrix))
    Cells() without a dot defaults to the activesheet
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  5. #5
    VBAX Contributor
    Joined
    Jul 2017
    Location
    Zurich
    Posts
    132
    Location
    Many thanks for the quick reply...that works now

Posting Permissions

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