Results 1 to 4 of 4

IF statement not working as expected?

Threaded View

Aland2929 IF statement not working as... 07-30-2009, 06:31 AM
Phil_V Re: IF statement not working... 07-30-2009, 06:42 AM
romperstomper Re: IF statement not working... 07-30-2009, 06:49 AM
Aland2929 Re: IF statement not working... 07-30-2009, 07:03 AM
  1. #1
    Forum Contributor
    Join Date
    06-11-2009
    Location
    Cape Town
    MS-Off Ver
    Microsoft 365
    Posts
    854

    IF statement not working as expected?

    Hi All,

    I have two worksheets named "Data" and "Product". I want to use the following macro to sort the records depending which sheet is active. If I am in the "Data" sheet, it does the sort in the "Product" sheet? I was expecting it to ignore the second IF statement when I am in the "Data" sheet? Please help.

    Sub RegionSort()
    '   Sort by Region
     Application.ScreenUpdating = False
     If Worksheets("Data").Visible Then
        Application.Goto Reference:="Data"
     End If
     If Worksheets("Product").Visible Then
        Application.Goto Reference:="Data2"
     End If
        Selection.Sort Key1:=Range("B4"), Order1:=xlAscending, Header:=xlGuess, _
            OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
            DataOption1:=xlSortNormal
        Range("A4").Select
     Application.ScreenUpdating = True
    End Sub
    Thank You
    Last edited by Aland2929; 07-30-2009 at 07:03 AM.

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