If function with a Pivot Table value

ibadk

New Member
Joined
Mar 10, 2011
Messages
11
Hey Guys,

I have in place a macro, and one of the inputs for the output of this Macro is data from a pivot table. The issue is, that one of my Row Label field values changes depending on the data set. For Example my Row label field is called Books, and in a typical month there are two types of books (Internal and External) however, some months there's only one. A part of my Macro will grab this data separately, first it will grab the external data, then the internal data, by changing the filter on the Row Field Label books. So my issue is, that in the months I only have one book (External for example, External book will always be there, it's the Internal book that's there some months but not others) my Macro will stop, and tell me that I don't have a data object (rightfully so). I want to write an If statement that tells the macro that If the Internal book Value doesn't exist in the Books Row Field, then to skip that portion of the code. How would I do this? Thanks
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
Code:
    wrkbook.Sheets(sheetname).Cells(startingrow + 1, 1) = "Interbook"
    wrkbook.Sheets(sheetname).Cells(startingrow + 1, 2) = "Market"
    wrkbook.Sheets(sheetname).Cells(startingrow + 2, 2) = iMarket.Value
    wrkbook.Sheets(sheetname).Cells(startingrow + 3, 2) = iComp.Value
    wrkbook.Sheets(sheetname).Cells(startingrow + 6, 2) = iMarket.Value
    wrkbook.Sheets(sheetname).Cells(startingrow + 7, 2) = iComp.Value
    wrkbook.Sheets(sheetname).Cells(startingrow + 2, 1) = pt.PivotFields("Interbook").PivotItems(1).Value
    wrkbook.Sheets(sheetname).Cells(startingrow + 2, 1).Font.Bold = True
    'If there were no internal books in the current month then the macro will skip over the code below and go straight to the bordering code
    
    wrkbook.Sheets(sheetname).Cells(startingrow + 6, 1) = pt.PivotFields("Interbook").PivotItems(2).Value
    wrkbook.Sheets(sheetname).Cells(startingrow + 6, 1).Font.Bold = True
If it helps this is what I have so far. An I want the if statement placed below the area where I have the comment. Once again, any help would be appreciated. Thanks in advance.
 
Upvote 0

Forum statistics

Threads
1,224,506
Messages
6,179,159
Members
452,892
Latest member
yadavagiri

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top