+ Reply to Thread
Results 1 to 4 of 4

Subscript out of range error(For karedog)

Hybrid View

ricklou Subscript out of range... 09-28-2017, 06:00 AM
karedog Re: Subscript out of range... 09-28-2017, 06:39 AM
ricklou Re: Subscript out of range... 09-29-2017, 04:16 AM
karedog Re: Subscript out of range... 09-29-2017, 04:21 AM
  1. #1
    Forum Contributor
    Join Date
    07-01-2012
    Location
    ZA
    MS-Off Ver
    Excel 2013
    Posts
    300

    Subscript out of range error(For karedog)

    Karedog I need your help please Macro 1 works but Macro 2 is giving an error -your help will be appreciated. Rep given for your help thanks Karedog

    Thanks Karedog
    Attached Files Attached Files

  2. #2
    Forum Guru karedog's Avatar
    Join Date
    10-03-2014
    Location
    Indonesia
    MS-Off Ver
    2003
    Posts
    2,971

    Re: Subscript out of range error(For karedog)

    ricklou, try this modified code according to new data layout :
    Sub KaredogMac2()
      Dim a(), b(), c As New Collection, d As New Collection, i As Long, x As String, y As String, z As String, v1, v2, v3
      Sheet1.Select
      a = Range("A1").CurrentRegion.Resize(, 2).Value
      b = Range("F1:H" & Cells(Rows.Count, "F").End(xlUp).Row).Value
      For i = 2 To UBound(a, 1)
          x = Trim$(a(i, 2))
          If Len(x) Then
             On Error Resume Next
                c.Add Key:=x, Item:=New Collection
             On Error GoTo 0
             c(x).Add a(i, 1)
          End If
      Next i
      For i = 1 To UBound(b, 1)
          x = Trim$(b(i, 1))
          y = Trim$(b(i, 2))
          z = Trim$(b(i, 3))
          If Len(x) * Len(y) * Len(z) Then
             On Error Resume Next
                Set v1 = c(x)
                Set v1 = c(y)
                Set v1 = c(z)
                If Err.Number <> 0 Then
                   On Error GoTo 0
                   GoTo skipper
                End If
             On Error GoTo 0
             For Each v1 In c(x)
                 For Each v2 In c(y)
                     For Each v3 In c(z)
                         d.Add Array(v1, v2, v3)
                     Next v3
                 Next v2
             Next v1
          End If
    skipper:
      Next i
      ReDim a(1 To d.Count, 1 To 3)
      i = 0
      For Each v1 In d
          i = i + 1
          a(i, 1) = v1(0)
          a(i, 2) = v1(1)
          a(i, 3) = v1(2)
      Next v1
      Range("N2").Resize(UBound(a, 1), UBound(a, 2)).Value = a
    End Sub
    If you want to change data from columns F-G-H to I-J-K, then change this code as well :
    'b = Range("F1:H" & Cells(Rows.Count, "F").End(xlUp).Row).Value
    b = Range("I1:K" & Cells(Rows.Count, "I").End(xlUp).Row).Value
    1. I care dog
    2. I am a loop maniac
    3. Forum rules link : Click here
    3.33. Don't forget to mark the thread as solved, this is important

  3. #3
    Forum Contributor
    Join Date
    07-01-2012
    Location
    ZA
    MS-Off Ver
    Excel 2013
    Posts
    300

    Re: Subscript out of range error(For karedog)

    Karedog thank you it works flawlessy -thank you for the help -REP given thanks

  4. #4
    Forum Guru karedog's Avatar
    Join Date
    10-03-2014
    Location
    Indonesia
    MS-Off Ver
    2003
    Posts
    2,971

    Re: Subscript out of range error(For karedog)

    You are welcome, thanks for marking the thread as solved and rep.points.

    Regards

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Run-time error '9': subscript out of range - error occurs on multiple computers except one
    By BrettE in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 02-06-2014, 11:19 PM
  2. Runtime Error - Subscript out of Range / Object Error
    By JHRice in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-04-2012, 05:14 PM
  3. Defining Array - Runtime error 9, Subscript out of range error
    By MaartenW in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-03-2012, 07:32 AM
  4. Runtime Error - Subscript out of range despite On Error statement
    By DoctorG in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-28-2006, 11:05 AM
  5. Subscript out of range error - save copy error
    By bg18461 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-13-2006, 11:53 AM
  6. [SOLVED] Type Mismatch error & subscript out of range error
    By Jeff Wright in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-14-2005, 03:06 PM

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