+ Reply to Thread
Results 1 to 2 of 2

VBA Help

  1. #1
    Registered User
    Join Date
    07-01-2015
    Location
    Scotland
    MS-Off Ver
    Mac 2011
    Posts
    1

    VBA Help

    The below VBA for fixing a worksheet, formatting and adding new rows between different values in Column B works but does not run for the whole worksheet. Am I missing something? Would appreciate any help I get.

    Thanks






    Sub SORTINGandFORMATTING()
    '
    ' SORTINGandFORMATTING Macro
    '

    '
    Columns("A:A").Select
    Application.ScreenUpdating = False

    Selection.NumberFormat = "0"
    Columns("A:B").Select
    Selection.Replace What:="yellow", Replacement:="Yellow", LookAt:=xlPart, _
    SearchOrder:=xlByRows, MatchCase:=False
    ActiveWorkbook.Worksheets("Test_28-06-2015").Sort.SortFields. _
    Clear
    ActiveWorkbook.Worksheets("Test_28-06-2015").Sort.SortFields. _
    Add Key:=Range("B:B"), SortOn:=xlSortOnValues, Order:=xlAscending _
    , DataOption:=xlSortNormal
    With ActiveWorkbook.Worksheets("Test_28-06-2015").Sort
    .SetRange Range("A:B")
    .Header = xlNo
    .MatchCase = False
    .Orientation = xlTopToBottom
    .SortMethod = xlPinYin
    .Apply

    Application.ScreenUpdating = False
    '
    Dim iRow As Integer, iCol As Integer
    Dim oRng As Range

    Set oRng = Range("b1")

    iRow = oRng.Column
    iCol = oRng.Column

    Do
    '
    If Cells(iRow + 1, iCol) <> Cells(iRow, iCol) Then
    Cells(iRow + 1, iCol).EntireRow.Insert shift:=xlDown
    iRow = iRow + 2
    Else
    iRow = iRow + 1
    End If
    '
    Loop While Not Cells(iRow, iCol).Text = ""
    '

    End With
    End Sub

  2. #2
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: VBA Help

    Your macro will stop at the first empty cell.

    Please Login or Register  to view this content.
    Normally we find the last used cell in a column and loop until we reach that row.

    eg for column 2:

    Please Login or Register  to view this content.

    Please Login or Register  to view this content.
    My General Rules if you want my help. Not aimed at any person in particular:

    1. Please Make Requests not demands, none of us get paid here.

    2. Check back on your post regularly. I will not return to a post after 4 days.
    If it is not important to you then it definitely is not important to me.

+ 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