Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Old James
Nov 20, 2003

Wait a sec. I don't know an Old James!

ZerodotJander posted:

Do a vlookup for each item from column A into column B, the ones that error out are the ones that are missing from column B.

Is there any resource that ranks functions based on how processor intensive they are? In this example a match, vlookup, or coutif would all get the job done but if you were doing this for large datasets which one would be the quickest to calculate?

Adbot
ADBOT LOVES YOU

Old James
Nov 20, 2003

Wait a sec. I don't know an Old James!

coyo7e posted:

Anybody who works with spreadsheets and doesn't know how to use $, go to google and start looking up "relative and absolute cell referencing". There are hundreds of videos on it, and after just a few minutes you'll increase the stability of your spreadsheets and the range of your abilities.

I come from a programming background so I take this stuff for granted but it's amazing how many people wrestle with this because they don't even know they can use $.

Or that F4 toggles between the various relative and absolute references for the columns and rows.

Old James
Nov 20, 2003

Wait a sec. I don't know an Old James!

DEUCE SLUICE posted:

My wife has hundreds of workbooks with 50k+ lines that she wants to dump into one consolidated database for easier reporting, but she's having trouble figuring out how to run reports from Excel once the stuff is in Access or whatever. Is there a good resource, either a book or online, that discusses how she can plug the two things together?

I saw an O'Reilly's book, Integrating Excel and Access, but it's from 2005.

It sounds like she wants to use functions on the entire set of data at once. If so packing it into an Access database won't do her much good as she will have to bring it back the data into Excel before she can run her functions on it. If she will only need subsets of the data at a time she can set up an ODBC connection to any Database tool to query data and have that subset automatically dumped into Excel, then she can use her functions on that subset.

Old James
Nov 20, 2003

Wait a sec. I don't know an Old James!

EDIT: ^^^^ I believe macros don't work on the Mac version of Excel.

sirbeefalot posted:



It was quicker for me to mock up a file for you than abstractly explain the formulas. Hopefully you can look at the formulas and pick up what I am trying to do. Just keep copying the block for each address down till you run out of space. You could modify the formulas to use them in a second and third column to fill out your paper when you print it out.

http://www.megaupload.com/?d=ZU9UO8AJ

Old James fucked around with this message at 00:10 on Dec 5, 2011

Old James
Nov 20, 2003

Wait a sec. I don't know an Old James!

Can someone help with an Excel 2010 question?

I upgraded to 2010 at work today and found they've enabled wildcards in countifs and sumifs. The problem is I have reports that use formulas like "=countif($A:$A,$D1)" and some of the fields in column D have wildcard characters in their string. So when the formula is looking at a field that has "S*" instead of giving a count of exactly that string it will count all strings that start with "S". I have searched online and found that I could do "=countif($A:$A,"S~*")" to get an exact match, but since my criteria is a range and not a string that does not fix it for me. Are there any 2010 users who could help me out?

I wish they had added an optional field in the formula that would let me turn wildcards off and made that the default as I have a number of reports which will break when other users upgrade to 2010 as well.

Old James
Nov 20, 2003

Wait a sec. I don't know an Old James!

Ronald McReagan posted:

stuff...

You are looking for the vlookup formula. If the beginning of the semester names as grades are in columns A and B and the end of semester names are in column D, your formula in E1 would be
code:
=vlookup($D1,$A:$B,2,false)
The formula looks through the first column of range $A:$B looking for an exact match to the value in $D1 and if it find the exact match it spits the results in the second column of that range. If it can't find a match it returns and error.

Old James
Nov 20, 2003

Wait a sec. I don't know an Old James!

Ron DeBruin http://www.rondebruin.nl/tips.htm Also has some great tips.

Old James
Nov 20, 2003

Wait a sec. I don't know an Old James!

You could do what you want with INDIRECT() but a better way is to use OFFSET().

What offset does is takes a starting range and then moves it x columns and y rows. You can even make it change width and height so you start out defining 1 cell and with offset the formula is now looking at a block of 6 cells, but it doesn't look like you need that aspect for your formula here.

=offset($A$1,1,2) will return the value in cell $C$2 because that is 1 row down and 2 columns to the right from $A$1. =offset($A$1,0,0) returns $A$1.

So if you want to values in $AA$1 and $AC$1 to be 2 and 3 respectively and you want the offsets to show the results from those two rows then your formula would be...

=SUM(offset($C$1,$AA$1-1,0)-offset($C$1,$AC$1-1,0),offset($O$1,$AA$1-1,0)-offset($E$1,$AC$1-1,0),offset($R$1,$AA$1-1,0)-offset($H$1,$AC$1-1,0),offset($N$1,$AA$1-1,0)-offset($N$1,$AC$1-1,0),offset($AL$1,$AA$1-1,0)-offset($AL$1,$AC$1-1,0),randbetween(-5,5))

Old James
Nov 20, 2003

Wait a sec. I don't know an Old James!

Try something like this in 4 columns for each day (since you are choosing 4 resources)

=CHOOSE(RANDBETWEEN(1,6),"A","B","C","D","E","F")

Over a very large dataset you should end up at roughly even distribution. But since it is random they will almost never be exact, if you need that then you aren't looking for a random allotment.

Old James fucked around with this message at 07:02 on Jan 5, 2012

Old James
Nov 20, 2003

Wait a sec. I don't know an Old James!

^^^^If you are sharing this file with others and they are scared whenever the macro security bar appears, you can do it with functions.

hog wizard, I am assuming your client name dropdown is in Report!$C$1 then in your "Client Information" table you would want to have

code:
=iferror(offset(Client!$A$1,match(Report!$C$1,Client!$A:$A,0)-1,row()-row(Report!$A$3)),"")
and in the "Schedule Information" table have

code:
=if(row()-row(Report!$A$16)>countif(Schedule!$A:$A,Report!$C$1),"",iferror(offset(Schedule!$A$1,
match(Report!$C$1,Schedule!$A:$A,0)-1+row()-row(Report!$A$17),column()-column(Report!$A$17)+1),""))
For this to work the Client and Schedule tabs must be sorted by client name.

Old James fucked around with this message at 23:41 on Jan 12, 2012

Old James
Nov 20, 2003

Wait a sec. I don't know an Old James!

Powdered Toast Man posted:

Having trouble with a sheet that is pulling from an external data source. Some details:

-The file itself is generated by an automated process on the database server, and is then emailed out to a group. It is initially generated in Excel 2003 format.

-The database connection is to MSSQL2005 through Microsoft Query and is calling a stored procedure. We have verified that the database connection itself is ok, and the stored procedure is also working properly.

-The end user opens the file in Excel 2007. At this point the imported data appears to be static, but if you select the range you can see the connection and everything looks ok, however:

-Refresh options are grayed out
-Clicking on the Refresh button does nothing. Literally nothing. You click it, and nothing happens. No errors, and the data does not update.

It is also worth noting that if you open the connection in Microsoft Query it will pull data there just fine. It simply isn't getting into the sheet.

Any ideas?

I don't work with database connections very often, but doesn't the end user have to have the database connection in their "My Data Sources" folder on Windows as well as the associated driver in order to do the refresh data? Maybe the end user machine where you are running it is missing the data source file.

Powdered Toast Man posted:

EDIT:

As an additional point, we were going to try unlinking and relinking the cells, so we found this:

Excel 2007 Help File posted:

Freeze data in an Excel table
Click the worksheet that contains the Excel table from which you want to remove the data connection.
On the formula bar, click the arrow next to the Name Box, and then click the name of the external data range from which you want to remove the data connection. The data range is then selected.
On the Tools tab, in the External Table Data group, click Unlink. The data range remains and still bears the same name, but the connection is deleted.

What the gently caress? Where is this "Tools tab" thing?

I think that means this...

Old James
Nov 20, 2003

Wait a sec. I don't know an Old James!

hog wizard posted:

DukAmok and Old James, thank you for those replies. They were very helpful. I really appreciate it.

Old James, it seems like if any of the cells next to the client name is blank, then it returns a value of 0. Is there a way I can make it return a blank?

Ah yes, if the cell is blank the offset formula returns 0. The versions below check to see if the cell is blank and return a blank value, whereas if the cell legitimately has a value of 0 of will still return 0.

code:
=iferror(if(offset(Client!$A$1,match(Report!$C$1,Client!$A:$A,0)-1,row()-row(Report!$A$3))="","",
offset(Client!$A$1,match(Report!$C$1,Client!$A:$A,0)-1,row()-row(Report!$A$3))),"")

=if(row()-row(Report!$A$16)>countif(Schedule!$A:$A,Report!$C$1),"",
iferror(if(offset(Schedule!$A$1,match(Report!$C$1,Schedule!$A:$A,0)-1+row()-row(Report!$A$17),
column()-column(Report!$A$17)+1)="","",offset(Schedule!$A$1,match(Report!$C$1,Schedule!$A:$A,0)
-1+row()-row(Report!$A$17),column()-column(Report!$A$17)+1)),""))
EDIT: added line breaks to the formulas to avoid breaking tables

Old James
Nov 20, 2003

Wait a sec. I don't know an Old James!

beejay posted:

stuff...

Sounds like a vlookup is in your future.
code:
=iferror(vlookup($A2,Sheet1!$A:$D,4,false),"")

Old James
Nov 20, 2003

Wait a sec. I don't know an Old James!

Pimpmust posted:

stuff...

code:
=large(C1:C3,1)+countif(C1:C3,large(C1:C3,1))-1

Old James fucked around with this message at 19:18 on Jan 13, 2012

Old James
Nov 20, 2003

Wait a sec. I don't know an Old James!

Powdered Toast Man posted:

I can't seem to get this ribbon to display. I've got the developer ribbon, but not this. How do you get it?

You have to have a table object on the sheet and select a cell within that table for the tab to appear. When I import data in 2007 or later it automatically creates the table object for me. For the purposes of the screen shot I made one by going to the Insert tab and clicking the second button (labelled Table, NOT PivotTable).

Old James
Nov 20, 2003

Wait a sec. I don't know an Old James!

ejstheman posted:

How do I dereference a cell that I have a text-format reference to? Like, if the function I'm looking for is called xyz, then I could get the concatenation of two random words from a wordlist that's stored in a1-a850 with:
code:
=CONCATENATE(xyz(ADDRESS(RANDBETWEEN(1,850),1)),xyz(ADDRESS(RANDBETWEEN(1,850),1)))

I know this was already answered, but I am not a fan of INDIRECT() so you can also do it with OFFSET().

code:
=CONCATENATE(XYZ(OFFSET(A1,RANDBETWEEN(1,850)-1,0)),XYZ(OFFSET(A1,RANDBETWEEN(1,850)-1,0)))

Old James
Nov 20, 2003

Wait a sec. I don't know an Old James!

DukAmok posted:

Any particular reason? I use indirect just because it was the first google hit when I was trying to solve the same issue.

Both INDIRECT() and OFFSET() are volatile functions which means they recalculated with every change to the workbook so extensive use of either will rape your CPU. However, of the two OFFSET() calculates faster.

INDEX() is not volatile, so the following might be a better then either of the answers we gave above.

code:
=CONCATENATE(XYZ(INDEX(A1:A850,RANDBETWEEN(1,850),1)),XYZ(INDEX(A1:A850,RANDBETWEEN(1,850),1)))

Old James fucked around with this message at 04:59 on Jan 27, 2012

Old James
Nov 20, 2003

Wait a sec. I don't know an Old James!

Boz0r posted:

Is it possible to test if the first 5 characters of a string are numbers, and then remove the rest of the string?

code:
=if(isnumber(left(A1,5)),left(A1,5),A1)

Boz0r posted:

EDIT: Also, how do I find the first non-number character in a string?

code:
Function NonNumber(RNG As Range)
    Dim i As Long
    Dim testint As Integer

    For i = 1 To Len(RNG.Cells(1, 1).Value)
        On Error GoTo Results
        testint = Mid(RNG.Cells(1, 1).Value, i, 1)
    Next i
    i = 0

Results:
    NonNumber = i

End Function

Old James
Nov 20, 2003

Wait a sec. I don't know an Old James!

bairfanx posted:

So, I've got a problem that's looking like it's going to take a lot more time than I expected:

I've got monthly metrics reports for a department of ~15 people. There are ~20 different categories that each person reports their activity under.

Is ther a convenient way to produce individual, year-to-date reports for each team member?

Right now, since we're only in January, it would obviously be pretty simple, but ideally I'd like to be able to pull from up to 12 months worth of either separate sheets or workbooks and have each individual's ytd report show each month as a separate column.

Right now I'm frustratingly playing around with PivotTables, but despite being only moderately skilled with Excel, I'm pretty confident there's a better way than this.

For a small team like this you could make a master table on one tab with each team member and their stats. In column A have something like "Old James: 2012 01", "Old James: 2012 02", etc. Then create a blank template for the report layout. Copy the template onto a new sheet for each team member with their name in cell A1. Then have the fields where you want values use formulas like "=iferror(vlookup(A1&text(date(2012,1,1),": yyyy mm"),master_table,2,false),"")" to pull the individual stats from the master table.

It's not elegant, but gets the job done for a small team. A better option would be to use Access.

Old James fucked around with this message at 22:11 on Feb 6, 2012

Old James
Nov 20, 2003

Wait a sec. I don't know an Old James!

A coworker asked me to help her fix a spreadsheet she updates which was created by her predecessor. Looking at it I saw some strange syntax in the formulas that I do not understand and Google was not very helpful.

code:
=SUMPRODUCT(--('Raw Data'!$AU$2:$AU$4820=0),--('Raw Data'!$DL$2:$DL$4820<=4))
From the context of where the formula is used it is supposed to function like a COUNTIFS() but I've never seen the "--" before. Could anyone help explain to me what that does?

Old James
Nov 20, 2003

Wait a sec. I don't know an Old James!

esquilax posted:

The stuff inside each parentheses evaluates to TRUE or FALSE. When you put a -- in front of it it multiplies by -1 twice, which turns the TRUE and FALSE into 1 and 0 respectively, which is the necessary syntax for the sumproduct() function. There are other ways to do the same thing but -- works.

Thanks, that makes some sense. Now that excel has countifs() I think I will stick with that instead, but good to know in case I run into it again.

Old James
Nov 20, 2003

Wait a sec. I don't know an Old James!

Xguard86 posted:

Short question: does anyone have a good resource for learning how to put if then statements into macros, specifically looking for certain strings in a cell and deleting that row?

I am building a vba macro to reformat a .csv dump from our internal project tracking system into a more user friendly format. Its all very simple formatting stuff until this part. I have zero VBA experience and no idea how to get logic in there.

I looked for tutorials online but they all seem too high level for what I'm trying to do.

http://www.techonthenet.com/excel/formulas/if_then.php

This should do what you want. Just change the range("A1") to the actual column with the cells you are looking and and change "xyz" to the criteria.

code:
sub delete_row()
   dim i as long
   dim last as long
   
   last = activesheet.usedrange.rows.count-1

   For i=last to 1 step -1
      if instr(activesheet.range("A1").offset(i,0).value,"xyz")>0 then
         activesheet.range("A1").offset(i,0).entirerow.delete
      end if
   next i
end sub

Old James
Nov 20, 2003

Wait a sec. I don't know an Old James!

Xguard86 posted:

sweet thanks, that looks like it will do the trick.

It iterates through the whole column starting at A, right? So I just need (whatever column)1 and it will step through until it hits a blank cell?

It runs till it reaches the last used row on the spreadsheet. So if column A stops at row 5, but column D has 200 rows it will continue to run through 150 blank cells in column A.

Xguard86 posted:

Second newbie question, can I just do the same for loop with a different column and string but not change variables for other fields?

Yes, change the range("A1") lines to reference the column you want to check and change "xyz" to your search sting (this is case sensitive).

This same process can be done with the .Find and .Findnext properties, which can ignore case and will run faster. However, if you are looking to teach yourself VBA wait on that until you feel a little more comfortable.

Old James
Nov 20, 2003

Wait a sec. I don't know an Old James!

You can do all 3 checks on the same pass through the text like so.

code:
Sub delete_row()
   Dim i As Long
   Dim last As Long
   
   last = ActiveSheet.UsedRange.Rows.Count - 1

   For i = last To 1 Step -1
      If InStr(ActiveSheet.Range("F1").Offset(i, 0).Value, "CarrierSpecs") > 0 _
      OR InStr(ActiveSheet.Range("F1").Offset(i, 0).Value, "EACopy") > 0 _
      OR If InStr(ActiveSheet.Range("F1").Offset(i, 0).Value, "Export") > 0 Then
         ActiveSheet.Range("A1").Offset(i, 0).EntireRow.Delete
      End If
   Next i
End Sub 
The underscore is there so I don't break tables with this code. It tells VB that there is a breakline and to continue reading the next line as part of the same string of code.

Old James
Nov 20, 2003

Wait a sec. I don't know an Old James!

Looks like you are using older syntax to sort. The way you are doing it limits you to 3 keys, but it is compatible with older versions of Excel.

You need to include the entire range in your sort, not just A2. Also, you were missing the order for each key otherwise Excel doesn't know if you want A->Z or Z->A. Finally, you are limited to the options xlYes/xlNo/xlGuess for the header.

code:
Worksheets("Macro_test").Range("A:H").Sort _
        Key1:=Range("G1"), _
        Order1:=xlAscending, _
        Key2:=Range("H1"), _
        Order2:=xlAscending, _
        Header:= xlYes
The header will always be the first row of the sort range. So in the case below it will make row 1 the header row. If the table is in A5:H500 then you can do either ...

code:
Worksheets("Macro_test").Range("A5:H500").Sort _
        Key1:=Range("G5"), _
        Order1:=xlAscending, _
        Key2:=Range("H5"), _
        Order2:=xlAscending, _
        Header:= xlYes
code:
Worksheets("Macro_test").Range("A6:H500").Sort _
        Key1:=Range("G6"), _
        Order1:=xlAscending, _
        Key2:=Range("H6"), _
        Order2:=xlAscending, _
        Header:= xlNo

Old James fucked around with this message at 20:16 on Feb 24, 2012

Old James
Nov 20, 2003

Wait a sec. I don't know an Old James!

It sounds like you want to number the rows instead of actually inserting new blank rows. So...

code:
sub rowvalue()
     dim i as long
     dim last as long
     
     For i = 0 to last
          if application.worksheetfunction.countA(range("1:1").offset(i,0))>0 then
               if iserror(application.worksheetfunction.large(range("A:A"),1)) then
                    range("A1").offset(i,0).value = 1
               else
                    range("A1").offset(i,0).value = _
                    application.worksheetfunction.large(range("A:A"),1) + 1
               end if
          end if
     next i
end sub

Old James
Nov 20, 2003

Wait a sec. I don't know an Old James!

It looks like the error is occurring when it tries to find the largest existing value in column A while column A is blank. Which is odd, because I told it if the large function returned an error to make the value 1. The version above would have picked up numbering after any existing value in column A. But the version below is simpler and just starts at 1.


code:
Sub rowvalueinsert()
     Dim i As Long
     Dim last As Long
     Dim counter as long
     
     Columns("A:A").Select
     Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
     counter = 1
    
     For i = 0 To last
          If Application.WorksheetFunction.CountA(Range("1:1").Offset(i, 0)) > 0 Then
               Range("A1").Offset(i, 0).Value = counter
               counter = counter + 1
          End If
     Next i
End Sub

Old James
Nov 20, 2003

Wait a sec. I don't know an Old James!

Xguard86 posted:

I know its been like 3 weeks but thanks, I actually ended up with pretty much that after playing with it over the weekend. VBA seems so simple and then things just... don't work. Very frustrating.

You're welcome.

Old James
Nov 20, 2003

Wait a sec. I don't know an Old James!

Tortilla Maker, this should parse the file names for contract numbers and then if it finds a match will add the file name and a hyperlink to the file in a column to the right on the sheet with the contract numbers. I haven't tested it out, so it might need some tweaking.

code:
sub TortillaMaker()
	dim RNG as range
	dim CELL as range
	dim Contracts as range
	dim Files as range
	const fpath = "C:\folder\records\"
	dim strLEFT as string
	dim strRIGHT as string
	dim strContract as string
	dim last as long
	
	'Set these ranges to the respective sheets and ranges containing the file names and contract numbers
	set Contracts = thisworkbook.sheets("Sheet1").range("C1:C400")
	set Files = thisworkbook.sheets("Sheet2").range("A1:A400")
	last = Contracts.usedrange.rows.count
	
	For each CELL in Files
		strRIGHT = Cell.value
		Do While instr(strRIGHT,"-")>0
			strLEFT = left(strRIGHT,instr(strRIGHT,"-")-1)
			strRIGHT = right(strRIGHT,len(strRIGHT)-instr(strRIGHT,"-"))
			if len(strLEFT)>= 5 AND len(strRIGHT)>=5 then
				if isnumeric(right(strLEFT,5)+0) AND isnumeric(left(strRIGHT,5)+0) then
					strContract = format(right(strLEFT,5)+0,"00000") & "-" & format(left(strRIGHT,5)+0,"00000")
					With Contracts
						set RNG = .find(what:=strContract, after:=.cells(1,last), lookin:=xlvalues, lookat:=xlwhole)
						If not RNG is nothing then
							RNG.offset(0,1).Hyperlinks.Add anchor:=RNG.offset(0,1), address:=fpath & CELL.value, TextToDisplay:=CELL.value
						end if
					End With
				end if
			end if
		Loop
	Next Cell
end sub

Old James
Nov 20, 2003

Wait a sec. I don't know an Old James!

Xguard86 posted:

what is wrong with this vba? I put a comment next to what it is flagging as an error. It says "object required". I'm sure its simple but I am bad at this. Can I not do " " for blank cell? Do I need something else?
code:
code...

You are setting rng1 to cell C1 and then deleting that cell, so I am guessing it is complaining because rng1 is now no longer set to a range value.

But there are other things in your code that make me think it will not work the way you intended. First, because you never reset rng1 to any other cell (looks like you are intending to with the i value, but you don't quite get there) each time it loops it is always checking the exact same value. But since you are deleting rows in the process your loop will end up skipping cells you want to check. Example, cell C3 = "Dallas Office", on the first loop it checks C1 it leaves the row and sets i = 1. On the second loop it checks C2, leaves the row and sets i = 2. Third pass it deletes row 3 and sets i=3. However, row 4 is now row 3 and when it loops again it looks at the value which was in C5 but now is in C4. So every time the loop deletes a row it misses out on checking the next row's value.

Here's how I'd do it, though someone else might have a better solution.
code:
sub delete_outside_offices()
   dim i as long
   dim last as long

   With thisworkbook.sheets("usr")
      last = .usedrange.rows.count - 1
      For i = last to 0 step -1
         if .range("C1").offset(i,0).value = "Dallas Office" then
            .range("C1").offset(i,0).entirerow.delete
         end if
      Next i
   End With

   With thisworkbook.sheets("qa")
      last = .usedrange.rows.count - 1
      For i = last to 0 step -1
         if .range("C1").offset(i,0).value = "Dallas Office" then
            .range("C1").offset(i,0).entirerow.delete
         end if
      Next i
   End With
End Sub

Old James
Nov 20, 2003

Wait a sec. I don't know an Old James!

Xguard86 posted:

ah I see. I never even thought about how deleting rows would screw up the loop.

Yeah, I learned that the hard way. With the code above I am checking the values from the bottom of the list going up. That way when I delete a row, the values below it which are shifted up have already passed the test while the untested rows above remain unchanged.

Old James fucked around with this message at 17:15 on Mar 19, 2012

Old James
Nov 20, 2003

Wait a sec. I don't know an Old James!

Bulls Hit posted:

Is there a way, when you update your excel spreadsheet, to have it upload to a table you uploaded to the web and update that table? Or do you always have to re-upload the spreadsheet data?

You can set it up to publish a range of cells as HTML every time you save the file. The just give it the path to your server.

http://office.microsoft.com/en-us/excel-help/put-excel-data-on-a-web-page-HP005256150.aspx

Old James
Nov 20, 2003

Wait a sec. I don't know an Old James!

do it posted:

I am trying to find out how many subscriptions were active during a given period. In Column A, I have the subscription start date, in Column B, the subscription end date. Using a list of weeks, I would like to determine how many subscriptions were active in that week.

I've uploaded a sample here: http://cl.ly/3I040N1R0Z0Y1K463X1q . Because subscription XX11 started on 7/17 and ended 7/29, it was active in week 7/9-7/15, week 7/16-7/22, and week 7/23-7/29. Because subscription XY23 started 7/9 and ended 7/18, it was active in week 7/9-7/15 and week 7/16-7/22. The other weeks had no subscriptions active.

Any help would be appreciated!

code:
Function ActiveSubscription(RNG as range, START as date, LENGTH as integer)
   dim i as long
   dim last as long
   dim ENDD as date
   dim COUNTER as long

   if rng.columns.count <>2 then
      ActiveSubscription = "Invalid Range"
      Exit Function
   end if

   END = dateadd("d",LENGTH-1,START)
   last = rng.rows.count
   For i=1 to last
      if RNG.cells(i,1).value >= START AND RNG.cells(i,1) <= ENDD then
         counter = counter + 1
      elseif RNG.cells(i,2).value >= START AND RNG.cells(i,2) <= ENDD then
         counter = counter + 1
      elseif RNG.cells(i,1).value <= START AND RNG.cells(i,2) >= ENDD then
         counter = counter + 1
      end if
   Next i

   ActiveSubscription = COUNTER
End Function

Old James fucked around with this message at 04:15 on Mar 27, 2012

Old James
Nov 20, 2003

Wait a sec. I don't know an Old James!

do it posted:

That is awesome, thank you!

You're welcome

quote:

I'm also trying to figure out how I can determine which week of a calendar quarter a date is in.

For example,
code:
1/6/12     2012 Q1 WK1
7/4/11     2011 Q3 WK2
However, =WEEKNUM only gives the week in the whole year, I need it to be reset at the beginning of each quarter (1/1,3/1,7/1,10/1).

code:
=IF(WEEKNUM(A1)<=13,"Q1-"&WEEKNUM(A1),IF(WEEKNUM(A1)<=26,"Q2-"&MOD(WEEKNUM(A1),13),IF(WEEKNUM(A1)<=39,"Q3-"&MOD(WEEKNUM(A1),26),"Q4-"&MOD(WEEKNUM(A1),39))))

Old James
Nov 20, 2003

Wait a sec. I don't know an Old James!

do it posted:

This is even more awesome. However, I'm getting back 2011 Q2-0 for 6/22/11 using

code:
=(YEAR(J63)&" "&(IF(WEEKNUM(J63)<=13,"Q1-"&WEEKNUM(J63),IF(WEEKNUM(J63)<=26,"Q2-"&MOD(WEEKNUM(J63),13),IF(WEEKNUM(J63)<=39,"Q3-"&MOD(WEEKNUM(J63),26),"Q4-"&MOD(WEEKNUM(J63),39))))))
(I only added YEAR).

This version will count 7 day periods starting with the first of the year (does not align with a calendar week). I'll look into tweaking it for calendar weeks once I am out of the office.

code:
=YEAR(A1)&" "&IF(A1>=DATE(YEAR(A1),10,1),"Q4-"&TEXT(ROUNDUP((A1-DATE(YEAR(A1),10,1)+1)/7,0),"00"),IF(A1>=DATE(YEAR(A1),7,1),"Q3-"&TEXT(ROUNDUP((A1-DATE(YEAR(A1),7,1)+1)/7,0),"00"),IF(A1>=DATE(YEAR(A1),4,1),"Q2-"&TEXT(ROUNDUP((A1-DATE(YEAR(A1),4,1)+1)/7,0),"00"),"Q1-"&TEXT(ROUNDUP((A1-DATE(YEAR(A1),1,1)+1)/7,0),"00"))))

Old James
Nov 20, 2003

Wait a sec. I don't know an Old James!

IF EXCEL.version >= 2007 then

code:
=COUNTIFS(coding_final!$K$2:$K$4,"<>"&categories!$A$10,coding_final!$K$2:$K$4,"<>"&categories!$A$11)
ELSE

code:
=counta(coding_final!$K$2:$K$4)-countif(coding_final!$K$2:$K$4,categories!$A$10)-countif(coding_final!$K$2:$K$4,categories!$A$11)
END IF



sorry felt especially nerdy....

Old James
Nov 20, 2003

Wait a sec. I don't know an Old James!

In my previous example it was checking for the two criteria against the one question (column K). Since you have two questions we just have to duplicate for the second one, in the code below I am assuming the second question is in column J.

code:
=COUNTIFS(coding_final!$J$2:$J$4,"<>"&categories!$A$10,coding_final!$J$2:$J$4,"<>"&categories!$A$11,
coding_final!$K$2:$K$4,"<>"&categories!$A$10,coding_final!$K$2:$K$4,"<>"&categories!$A$11)

Old James
Nov 20, 2003

Wait a sec. I don't know an Old James!

My example was only counting rows 2 through 4 since that was what you used in your original example. So the max possible with my formula would be 3 (3 rows where neither of the answers were used for both questions). When you changed the rows to look at 2 through 49 you ended up counting 34 of the 48 rows had neither answer to both questions.

I can't tell you if that is high or low without seeing the data myself. But with a sample that size you should be able to scan through it to eyeball if about 30% of the rows used one of the two answers.

Old James
Nov 20, 2003

Wait a sec. I don't know an Old James!

GregNorc posted:

Aha. So I would have this report 1 if both met the critera, then sum all the rows? I see.

I eyeballed it, but it'd be nice to have a formula for follow-up study which will have way too much data to eyeball it.

Correct, this formula looks at J2 and asks "Does this say 'No Problem'?" If no then it asks "Does this say 'None Mentioned'?" if no then it looks at K2 and asks the same two questions. If it passes all 4 questions it flags it as a 'True' and counts how many were true.

This is the formula you want to use for a large dataset. I was just suggesting you eyeball the data since you didn't sound like you trusted the results to help you feel more comfortable with the formula.

Adbot
ADBOT LOVES YOU

Old James
Nov 20, 2003

Wait a sec. I don't know an Old James!

GregNorc posted:

Aha... then something's wrong on my end since it's returning 34... Not a huge deal, the sample was small enough I was able to do it manually.

Can you upload the file somewhere?

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply