Results 1 to 4 of 4

Thread: VBA Code Help
Thanks Thanks: 0 Likes Likes: 0

  1. #1
    Board Regular
    Join Date
    Sep 2005
    Posts
    752
    Post Thanks / Like
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Default VBA Code Help

    I have a list of 324 sets of data in columns that are identical in size

    I tried using Record Macro then changing a few lines of code but received errors on a few lines of code.
    The new lines of code are for adjusted cell columns,

    Range(aRng & Range("AXO2").Value & ":" & aRng & Range("AXO3").Value)

    The code below is the Record Macro
    Sub SortDelete()

    Range("BL2:BN326").Select
    ActiveWorkbook.Worksheets("FLRLSets").Sort.SortFields.Clear
    ActiveWorkbook.Worksheets("FLRLSets").Sort.SortFields.Add Key:=Range( _
    "BN2:BN326"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
    xlSortNormal
    With ActiveWorkbook.Worksheets("FLRLSets").Sort
    .SetRange Range("BL2:BN326")
    .Header = xlGuess
    .MatchCase = False
    .Orientation = xlTopToBottom
    .SortMethod = xlPinYin
    .Apply
    End With
    Range("BL2:BN131").Select
    Selection.Delete Shift:=xlUp
    Range("AXQ1").Select
    End Sub

    ===========================================================================
    This is the code I tried to use:

    Sub SortDelete1()

    Dim aRng As String

    aRng = Sheets("FLRLSets").Range("AXO1").Value

    With ActiveSheet
    For Each cll In .Range(aRng & Range("AXO2").Value & ":" & aRng & Range("AXO3").Value).Cells

    .Range("AXO4").Value = cll.Value


    SortDelete2


    Next cll
    End With

    End Sub


    Sub SortDelete2()

    Dim aRng As String
    Dim bRng As String


    Application.ScreenUpdating = False

    aRng = Sheets("FLRLSets").Range("AXO5").Value
    bRng = Sheets("FLRLSets").Range("AXO7").Value

    Sheets("FLRLSets").Select

    Range(aRng & Range("AXM2").Value & ":" & bRng & Range("AXM3").Value).Select

    ActiveWorkbook.Worksheets("FLRLSets").Sort.SortFields.Clear
    ActiveWorkbook.Worksheets("FLRLSets").Sort.SortFields.Add Key:=Range( _

    "aRng & Range("AXM2").Value & ":" & bRng & Range("AXM3").Value"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _ "this line gives an error
    xlSortNormal
    With ActiveWorkbook.Worksheets("FLRLSets").Sort
    .SetRange Range("AXM2").Value & ":" & bRng & Range("AXM3").Value") 'this line of code gives an error
    .Header = xlGuess
    .MatchCase = False
    .Orientation = xlTopToBottom
    .SortMethod = xlPinYin
    .Apply 'This line gives an error
    End With

    Range(aRng & Range("AXO8").Value & ":" & bRng & Range("AXO9").Value).Select
    Selection.Delete Shift:=xlUp


    Sheets("FLRLSets").Select
    Range("AXQ1").Select

    Application.ScreenUpdating = True

    End Sub

  2. #2
    MrExcel MVP
    Junior Admin
    Joe4's Avatar
    Join Date
    Aug 2002
    Posts
    50,715
    Post Thanks / Like
    Mentioned
    57 Post(s)
    Tagged
    11 Thread(s)

    Default Re: VBA Code Help

    Note the difference in structure between this:
    Code:
    Range(aRng & Range("AXO2").Value & ":" & aRng & Range("AXO3").Value)
    and this:
    Code:
    Range("AXM2").Value & ":" & bRng & Range("AXM3").Value")
    Your second value is just a string, not a range (because you are not enclosing the whole thing in Range(...), like you do the first. Note the parentheses, and how quickly you close out the first range reference.
    Your other errored line has a similar issue.

    Give it a try fixing it up, and see if you can get it. If not, post back.
    Last edited by Joe4; May 21st, 2019 at 09:22 AM.
    TIPS FOR FINDING EXCEL SOLUTIONS
    1. Use the built-in Help that comes with Excel/Access
    2. Use the Search functionality on this board
    3. A lot of VBA code can be acquired by using the Macro Recorder.

    "Give a man a fish, feed him for a day. Teach a man to fish, feed him for life!"

  3. #3
    Board Regular
    Join Date
    Sep 2005
    Posts
    752
    Post Thanks / Like
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Default Re: VBA Code Help

    OK Thanks for all your help. I changed the code and worked.

    Thanks you!!

  4. #4
    MrExcel MVP
    Junior Admin
    Joe4's Avatar
    Join Date
    Aug 2002
    Posts
    50,715
    Post Thanks / Like
    Mentioned
    57 Post(s)
    Tagged
    11 Thread(s)

    Default Re: VBA Code Help

    You are welcome.
    TIPS FOR FINDING EXCEL SOLUTIONS
    1. Use the built-in Help that comes with Excel/Access
    2. Use the Search functionality on this board
    3. A lot of VBA code can be acquired by using the Macro Recorder.

    "Give a man a fish, feed him for a day. Teach a man to fish, feed him for life!"

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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