Results 1 to 4 of 4

Need help with If/ElseIf based on worksheets

Threaded View

  1. #1
    Registered User
    Join Date
    11-04-2015
    Location
    California
    MS-Off Ver
    2011
    Posts
    6

    Need help with If/ElseIf based on worksheets

    Hello!

    First post ever but I've been snooping for a while

    I created a macro that opens a worksheet generated from my work, and it pivots the data to a more user-friendly format. It works perfectly with what I want to do. However, I want to scale it for a much larger data set.

    sub example()
    Dim filename As String
    Workbooks.Open filename
    
    'Grabs data from source worksheet
    Sheets("Call Report").Select
    ActiveWorkbook.PivotChaches.Create(SourceType:=xlDatabase, SourceData:="Call Report!R1C1:R" & DynamicRangeVariable & "C24",_
    Version:=xlPivotTableVersion14). '''code continues to create pivot
    The issue I run into is that if the data is pulled from a large sample size, the raw data will be split into two worksheets named "Call Report" and "Call Report (2)".

    How can I create an If/Else (or any other loop) statement where if only 1 sheet of source data is found, it will run the entire code I already built. However, if two sources are found, it will run a new code that consolidates multiple sheets to be able to create a single pivot.

    I'd imagine it would be something like this but I don't know the VBA conditions for it. Please ignore the obvious syntax errors below. I just want to write out a map for what I hope will work.

    If ("Call Report"==1 && "Call Report (2)"==0) Then
     My code
     Exit Sub
    
    Else If ("Call Report"==1 && "Call Report (2)"==1) Then
     New code to consolidate ranges
     My code to create pivot from new range
     Exit Sub
    
    Else If CStr(filename)="False" Then
     Exit Sub
    ' Is it even possible to have 2 Else If statements for 1 If like in java or c++?

    Thanks!
    Last edited by nzo12; 11-06-2015 at 01:16 AM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. ElseIf Without If
    By HarryGreenwood in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-06-2015, 05:12 AM
  2. Code stepping in to elseif statement when elseif is definitely not true
    By DFrank231 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 02-13-2013, 05:31 PM
  3. If Elseif elseif problem
    By tjbillund in forum Excel General
    Replies: 3
    Last Post: 08-10-2011, 07:02 AM
  4. [SOLVED] if elseif
    By flow23 in forum Excel General
    Replies: 0
    Last Post: 11-14-2005, 10:15 AM
  5. Re: IF..Then..ELSE.. ELSEIF
    By rjamison in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-13-2005, 08:05 PM
  6. [SOLVED] IF..Then..ELSE.. ELSEIF
    By ole_ in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-20-2005, 11:06 AM
  7. If, ElseIf
    By mast in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-26-2005, 09:06 AM

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