Finding the word False in an Excel Worksheet

Hi, I'm back.

I am trying to find the word "FALSE" in Column D of my worksheet and
then copy the whole row to a new sheet.
Code so far:

$xl = New-Object -comobject Excel.Application
$xl.Visible = $true
$xl.DisplayAlerts = $False
$xlCellTypeLastCell = 11
#Open spreadsheet
$wb = $xl.workbooks.open("C:\Temp\test.xls")
# rename the Worksheet. 30 charactor limit
$ws1 = $wb.worksheets | where {$_.name -eq "xml_source"}
$ws2 = $wb.worksheets | where {$_.name -eq "Report"}
$ws3 = $wb.worksheets | where {$_.name -eq "sheet3"}
# Activate sheet 1
[void]$ws1.activate()
#Start Test
$i = 2
For ($i = $zRow; $i -eq $R; $i++) {
   If ($ws1.Cell.Value($i, 4) = "FALSE") {
	$range4=$ws1.range("${i}:$i")
	$range4.Copy()
	$ws2.Activate
	$ws2.Cells.Item($i,1).PasteSpecial(-4163)
 	}
 }

The problem is, I get this error:

ERROR: You cannot call a method on a null-valued expression.
ERROR: At line:29 char:23
ERROR: +    If ($ws1.Cell.Value( <<<< $i, 4) = "FALSE") {

I am thinking that it does not like the word "FALSE" but i might be
overthinking.

Any ideas?

TIA,

OldDog
0
OldDog
5/11/2010 3:34:41 PM
windows.powershell 690 articles. 0 followers. Follow

6 Replies
1249 Views

Similar Articles

[PageSpeed] 26

Try coding it as

   If ($ws1.Cell.Value($i, 4) -eq "FALSE") {

  - Larry


On 5/11/2010 10:34 AM, OldDog wrote:
> Hi, I'm back.
>
> I am trying to find the word "FALSE" in Column D of my worksheet and
> then copy the whole row to a new sheet.
> Code so far:
>
> $xl = New-Object -comobject Excel.Application
> $xl.Visible = $true
> $xl.DisplayAlerts = $False
> $xlCellTypeLastCell = 11
> #Open spreadsheet
> $wb = $xl.workbooks.open("C:\Temp\test.xls")
> # rename the Worksheet. 30 charactor limit
> $ws1 = $wb.worksheets | where {$_.name -eq "xml_source"}
> $ws2 = $wb.worksheets | where {$_.name -eq "Report"}
> $ws3 = $wb.worksheets | where {$_.name -eq "sheet3"}
> # Activate sheet 1
> [void]$ws1.activate()
> #Start Test
> $i = 2
> For ($i = $zRow; $i -eq $R; $i++) {
>     If ($ws1.Cell.Value($i, 4) = "FALSE") {
> 	$range4=$ws1.range("${i}:$i")
> 	$range4.Copy()
> 	$ws2.Activate
> 	$ws2.Cells.Item($i,1).PasteSpecial(-4163)
>   	}
>   }
>
> The problem is, I get this error:
>
> ERROR: You cannot call a method on a null-valued expression.
> ERROR: At line:29 char:23
> ERROR: +    If ($ws1.Cell.Value(<<<<  $i, 4) = "FALSE") {
>
> I am thinking that it does not like the word "FALSE" but i might be
> overthinking.
>
> Any ideas?
>
> TIA,
>
> OldDog
0
Larry__Weiss
5/11/2010 3:40:00 PM
On May 11, 10:40=A0am, Larry__Weiss <l...@airmail.net> wrote:
> Try coding it as
>
> =A0 =A0If ($ws1.Cell.Value($i, 4) -eq "FALSE") {
>
> =A0 - Larry
>
> On 5/11/2010 10:34 AM, OldDog wrote:
>
>
>
> > Hi, I'm back.
>
> > I am trying to find the word "FALSE" in Column D of my worksheet and
> > then copy the whole row to a new sheet.
> > Code so far:
>
> > $xl =3D New-Object -comobject Excel.Application
> > $xl.Visible =3D $true
> > $xl.DisplayAlerts =3D $False
> > $xlCellTypeLastCell =3D 11
> > #Open spreadsheet
> > $wb =3D $xl.workbooks.open("C:\Temp\test.xls")
> > # rename the Worksheet. 30 charactor limit
> > $ws1 =3D $wb.worksheets | where {$_.name -eq "xml_source"}
> > $ws2 =3D $wb.worksheets | where {$_.name -eq "Report"}
> > $ws3 =3D $wb.worksheets | where {$_.name -eq "sheet3"}
> > # Activate sheet 1
> > [void]$ws1.activate()
> > #Start Test
> > $i =3D 2
> > For ($i =3D $zRow; $i -eq $R; $i++) {
> > =A0 =A0 If ($ws1.Cell.Value($i, 4) =3D "FALSE") {
> > =A0 =A0$range4=3D$ws1.range("${i}:$i")
> > =A0 =A0$range4.Copy()
> > =A0 =A0$ws2.Activate
> > =A0 =A0$ws2.Cells.Item($i,1).PasteSpecial(-4163)
> > =A0 =A0}
> > =A0 }
>
> > The problem is, I get this error:
>
> > ERROR: You cannot call a method on a null-valued expression.
> > ERROR: At line:29 char:23
> > ERROR: + =A0 =A0If ($ws1.Cell.Value(<<<< =A0$i, 4) =3D "FALSE") {
>
> > I am thinking that it does not like the word "FALSE" but i might be
> > overthinking.
>
> > Any ideas?
>
> > TIA,
>
> > OldDog- Hide quoted text -
>
> - Show quoted text -

Thanks, same error:

ERROR: You cannot call a method on a null-valued expression.
ERROR: At line:29 char:24
ERROR: +     If ($ws1.Cell.Value( <<<< $i, 4) -eq "FALSE") {

*** PowerShell Script finished. ***

0
OldDog
5/11/2010 5:39:03 PM
On May 11, 10:40=A0am, Larry__Weiss <l...@airmail.net> wrote:
> Try coding it as
>
> =A0 =A0If ($ws1.Cell.Value($i, 4) -eq "FALSE") {
>
> =A0 - Larry
>
> On 5/11/2010 10:34 AM, OldDog wrote:
>
>
>
> > Hi, I'm back.
>
> > I am trying to find the word "FALSE" in Column D of my worksheet and
> > then copy the whole row to a new sheet.
> > Code so far:
>
> > $xl =3D New-Object -comobject Excel.Application
> > $xl.Visible =3D $true
> > $xl.DisplayAlerts =3D $False
> > $xlCellTypeLastCell =3D 11
> > #Open spreadsheet
> > $wb =3D $xl.workbooks.open("C:\Temp\test.xls")
> > # rename the Worksheet. 30 charactor limit
> > $ws1 =3D $wb.worksheets | where {$_.name -eq "xml_source"}
> > $ws2 =3D $wb.worksheets | where {$_.name -eq "Report"}
> > $ws3 =3D $wb.worksheets | where {$_.name -eq "sheet3"}
> > # Activate sheet 1
> > [void]$ws1.activate()
> > #Start Test
> > $i =3D 2
> > For ($i =3D $zRow; $i -eq $R; $i++) {
> > =A0 =A0 If ($ws1.Cell.Value($i, 4) =3D "FALSE") {
> > =A0 =A0$range4=3D$ws1.range("${i}:$i")
> > =A0 =A0$range4.Copy()
> > =A0 =A0$ws2.Activate
> > =A0 =A0$ws2.Cells.Item($i,1).PasteSpecial(-4163)
> > =A0 =A0}
> > =A0 }
>
> > The problem is, I get this error:
>
> > ERROR: You cannot call a method on a null-valued expression.
> > ERROR: At line:29 char:23
> > ERROR: + =A0 =A0If ($ws1.Cell.Value(<<<< =A0$i, 4) =3D "FALSE") {
>
> > I am thinking that it does not like the word "FALSE" but i might be
> > overthinking.
>
> > Any ideas?
>
> > TIA,
>
> > OldDog- Hide quoted text -
>
> - Show quoted text -

I left out the part where I defined $zRow and $R

$row =3D 2
$xRow =3D 2
$zRow =3D 2
$xl =3D New-Object -comobject Excel.Application
$xl.Visible =3D $true
$xl.DisplayAlerts =3D $False
$xlCellTypeLastCell =3D 11
#Create spreadsheet
$wb =3D $xl.workbooks.open("C:\Temp\test.xls")
# rename the Worksheet. 30 charactor limit
$ws1 =3D $wb.worksheets | where {$_.name -eq "xml_source"} #<-------
activate()s sheet 1
$ws2 =3D $wb.worksheets | where {$_.name -eq "Report"} #<-------
activate()s sheet 2
$ws3 =3D $wb.worksheets | where {$_.name -eq "sheet3"} #<-------
activate()s sheet 3
# Activate sheet 1
[void]$ws1.activate()
#Start Test

$mainRng =3D $ws1.UsedRange.Cells
$RowCount =3D $mainRng.Rows.Count
$R =3D $RowCount
$R =3D $R + 1
$yRange =3D ($zRow,1)
$yRange.Select

For ($i =3D $zRow; $i -lt $R; $i++) {
   Write-Host $i $R
    If ($ws1.Cell.Value($i, 4) -eq "FALSE") {
	$range4=3D$ws1.range("${i}:$i")
	$range4.Copy()
	$ws2.Activate
	$ws2.Cells.Item($i,1).PasteSpecial(-4163)
 	}
 }
0
OldDog
5/11/2010 5:50:04 PM
OldDog wrote:
 >>> ERROR: You cannot call a method on a null-valued expression.
 >>> ERROR: At line:29 char:23
 >>> ERROR: +    If ($ws1.Cell.Value(<<<<    $i, 4) = "FALSE") {
 >>

What does this do?   What documentation did you see it in?

     If ($ws1.Cell.Value($i, 4) -eq "FALSE") {

Something seems odd about indexing a value and not indexing a cell
and then asking for that value.

Perhaps this article could be helpful
http://www.wapshere.com/missmiis/powershell-retrieving-data-from-excel

  - Larry


0
Larry__Weiss
5/11/2010 6:59:08 PM
On May 11, 1:59=A0pm, Larry__Weiss <l...@airmail.net> wrote:
> OldDog wrote:
>
> =A0>>> ERROR: You cannot call a method on a null-valued expression.
> =A0>>> ERROR: At line:29 char:23
> =A0>>> ERROR: + =A0 =A0If ($ws1.Cell.Value(<<<< =A0 =A0$i, 4) =3D "FALSE"=
) {
> =A0>>
>
> What does this do? =A0 What documentation did you see it in?
>
> =A0 =A0 =A0If ($ws1.Cell.Value($i, 4) -eq "FALSE") {
>
> Something seems odd about indexing a value and not indexing a cell
> and then asking for that value.
>
> Perhaps this article could be helpfulhttp://www.wapshere.com/missmiis/pow=
ershell-retrieving-data-from-excel
>
> =A0 - Larry

This works:

If ($ws1.Cells.Item($i,4).Text -eq "FALSE") {

Thanks for the help
0
OldDog
5/11/2010 8:21:12 PM

"OldDog" <mikef2691@comcast.net> wrote in message 
news:b45f069a-fc92-4bef-aa94-ec492367c086@a21g2000yqn.googlegroups.com...

> The problem is, I get this error:
>
> ERROR: You cannot call a method on a null-valued expression.
> ERROR: At line:29 char:23
> ERROR: +    If ($ws1.Cell.Value( <<<< $i, 4) = "FALSE") {
>
> I am thinking that it does not like the word "FALSE" but i might be
> overthinking.
>
> Any ideas?


What does the 4 mean?  Also, have you tried single quotes instead of double?

E.g.  maybe it's being evaluated and substituted unexpectedly?

PS C:\> dir variable:false

Name                           Value
----                           -----
false                          False


Good luck

Robert
---  

0
Robert
5/11/2010 9:13:31 PM
Reply:

Similar Artilces:

Existing word documents made on PC
Version: 2008 Operating System: Mac OS X 10.5 (Leopard) Processor: Intel I have a number of documents made on a PC that include images - scanned, from the internet, etc. They look fine when opened by Word for PC, but when the same file is opened by me using Office 08 for Mac, some (not all) of the pictures appear absolutely minute, in the top left of the image box. The image box is still there, so the text alignment is not affected, but the rest of the text box is blank. I have even had a colleague open the file on her PC to show me the image is fine, then email me the same image - with the s...

I need to compare 3 numbers and find the one in the middle
I have three numbers in a single row and would like to identify the middle number enter that number in another cell. Example: 1st # 2nd # 3rd # result 628 678 720 678 655 625 700 655 748 720 725 725 is there a function in excel that can do this? Thanks, Eddie Try =LARGE(A1:C1,2) VBA Noo -- VBA Noo ----------------------------------------------------------------------- VBA Noob's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=3383 View this thread: http://www.excelforum.com/showthread.php?threadid=56811 fasteddie wrote.....

How can I add Paste Special to the Word 2007 context menu?
Excel 2007's context menu includes Paste Special; Word's does not. I have frequent need for Paste Special in Word and the many trips to the Ribbon get tiresome. I'd like to know how to add commands to the context menu in general, but a solution for Paste Special is the immediate need. See http://gregmaxey.mvps.org/Customize_Word2007_SC_Menu_Programatically.htm -- <>>< ><<> ><<> <>>< ><<> <>>< <>><<> Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://...

Find Duplicate names and delate
Dear experts, I have a small doubt could you clarify that??? That is I find duplicate name but I want to delete one name only, if I filter DUPLICATE….. both names are showing… 1. Select the range of data including the header. You need to have headers for these columns 2. From menu Data>Filter>Advanced Filter>Copy to another location 3. In 'copy to' specify the target cell and check 'Unique records only' 4. Click OK will give you the unique list -- Jacob "Find Duplicate names and delate" wrote: > Dear experts, > I have a small ...

Publisher cuts off text from word file that I am pasting into tex.
What does "Type your message here" mean to you? -- Ed Bennett - MVP Microsoft Publisher http://www.mvps.org/the_nerd/ Before reading this message, view the disclaimer: http://mvps.org/the_nerd/disclaim.htm Let me guess the question... You paste Word text into a Publisher text box and it doesn't fit. -- Mary Sauer MS MVP http://office.microsoft.com/ http://www.msauer.mvps.org/ news://msnews.microsoft.com "DeborahKB" <DeborahKB@discussions.microsoft.com> wrote in message news:F29CD723-545B-4A7C-8ACA-DD5092DCE101@microsoft.com... > Ooooooooh, Mary...

how do i get negative numbers in brackets in Excel
i find i cannot enter negative numbers in accounts in brackets but this is the accounting convention is it hidden in excel or do i need a plug in Hi Maverick, Enter numbers using the minus symbol, but format your cells: Format => Cells => Number [tab] and in the Type box, enter "#,##0.00_ ;[Red](#,##0.00) " (without the quotation marks). Ewan. "maverick accountant" wrote: > i find i cannot enter negative numbers in accounts in brackets > but this is the accounting convention > is it hidden in excel > or do i need a plug in ...

Excel 2002 Charting on a rolling basis
Excel 2002 I have created a Line graph to plot data over 52 weeks. The x axis is Weeks and the y axis is Hours. The graph is a separate worksheet.I want to graph the data on a rolling basis so that each time i enter data, the graph only displays the current week and the previous 4 weeks, so being on a rolling basis and the graph not being cluttered. Hi have a look at http://www.tushar-mehta.com/excel/newsgroups/dynamic_charts/index.html http://peltiertech.com/Excel/Charts/Dynamics.html#DynoLast12 for creating dynamic charts -- Regards Frank Kabel Frankfurt, Germany ...

Excel files reporting read only
I have an issue where a user I provide support for is being told that a file that has not been opened for a couple of months is reporting as being locked for editing by the last user to save the file (in some cases these users no longer exist on our network). When you check the open files on the server, these files are not showing as open. If teh user clicks to close, and then immediatley re-opens the file it opens as normal. There are no temporary files in the folder that the files are located in and I have cleared the temp folders on the client and on the server. The user has full control...

Autofill Worksheets
Is there a way in Excel 2000 to rename the first two worksheets and then use an autofill type feature to add more worksheets with a series of names? For example, name one worksheet January, the next one February, then insert new worksheets that would be automatically named the consecutive months. Bonnie Hi Bonnie i would probably approach it this way, choose tools / options / general change "sheets in a new workbook" to 12 open a new workbook - it will have 12 sheets go back into tools / options / general and set the sheeets back to 3 then run the following code ---- Sub n...

Updating GAL from Excel?
Hello all, Can anyone recommend a tool for updating a global address list from an excel spreadsheet? Im not sure if such a thing exists but this would be a major convenience. I have an excel spreadsheet with my entire corporations address information and the execs would like to rely on the GAL for finding contact information. This would take me hours to do manually and having a tool or a script that can import or update fields would make the labor much simplier. I appreciate your responses. Keith. On Fri, 7 Oct 2005 08:41:03 -0700, "Keith" <Keith@discussions.microso...

Find a Value the first Time It Occurs
I have a row of values that shows the total cumulative number of sales of items by month. Occasionally, there may be no sales in a month for an item so the cumulative value would stay the same for more than one month. I want to select a number in the row the first time it occurs and not select it if it repeats. What are you wanting to do with the info? To return position (column number) of number 1234 within row 2: =MATCH(1234,2:2,0) A formula that signals it's the first occurence: =COUNTIF($A2:A2,A2)=1 This could be used in a helper row, or as a conditional format f...

Finding a Median
I'm trying to write a query that will return a median for various values taken from a previous query. I've seen some suggestions in my searching, but I haven't been able to get them working. They are also all from before 2003 and refer to Access 97 and 2000. Has any functionality been added to 2003 for this? Or is there a non- code-based way to do it? I've seen it suggested to write a code to open the query, sort it, find the total number of records, divide it in half, then seek out the middle record using that value. I'm still very green when it comes to code, though...

Excel won't open spreadsheet #2
Thank you. The first option worked. opty -- opty ----------------------------------------------------------------------- optyk's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=1533 View this thread: http://www.excelforum.com/showthread.php?threadid=26959 ...

INSERT Option in Word 2003 problem
When I click on INSERT option, the dropdown list repeats previously inserted word forever. I need to scroll through hundreds of the same word before i get to SYMBOLS or other options. Any ideas how to fix it. I tried repairing the installation and total re-installation, nothing works. In Tools | Customize, click the Toolbars tab. In the list of toolbars, select "Menu Bar" and then click Reset. Does that help? If/when you are prompted to save normal.dot, choose to do so. -- Stefan Blom Microsoft Word MVP "b***n" <b***n@discussions.microsof...

Will Excel 2004 run on SnowLeopard OS X 10.6?
Operating System: Mac OS X 10.6 (Snow Leopard) Processor: Intel I'm a SW developer who uses a lot of VBA for Excel programing, for automaation and macros. Besides that, my customers use the spreadsheets I develop in Office for PC's. I know Office 2008 has no VBA for Excel, but I really need it. Can I install Office 2004 in my computer and will it run under Snow Leopard, so that I can keep on using VBA with Excel? Yes -- But do a fresh install. Don't try to 'migrate' Office from an earlier version of the OS if you're upgrading to 10.6 & you will have to use t...

Find/Replace in RichEdit 2.0
I'm using Windows ME and I've switched from RichEdit 1.0 to 2.0 for my CRichEditDoc/View application so that I can use the ITextDocument interface and can do things such as suspend/resume the Redo buffer. Problem is, now the Find/Replace dialogs don't seem to do anything. If I revert back to RichEdit 1.0 they do! What's going on? BUMP! adriangibbons@yahoo.co.uk (Adrian Gibbons) wrote in message news:<34a2acd5.0404130713.123dbaab@posting.google.com>... > I'm using Windows ME and I've switched from RichEdit 1.0 to 2.0 for my > CRichEditDoc/View application...

OK, a really tricky one now for Excel gurus!
A perfect response before, this time a little trickier! I have two data sources: Data A) a column of approx. 3000 cells featuring the 'Post Code' only from a database of addresses. Data B) The Australian postcode database as found and downloaded from the below link: http://www1.auspost.com.au/postcodes/index.asp?sub=2 What I want to happen is each postcode from source 'A' to match up with the corresponding post code from source 'B' (this is in column A). Once it matches, the 'Delivery Office' (column E) is to appear in column B of Data Source Sheet A......

Find (but not find)
My program takes a name from sheet3 goes to sheet1 to Find the name. If it cannot find name, how do you do an If/End to Exit Do while or find out if name has been founf? I have "On Error Resume Next" in program. Thanks again for all your help Gordon As ALWAYS, post your code for comments & suggestions. -- Don Guillett Microsoft MVP Excel SalesAid Software dguillett1@austin.rr.com "Gordon" <gwelch1938@yahoo.com> wrote in message news:1184612089.486737.144020@n60g2000hse.googlegroups.com... > My program takes a name from sheet3 goes to sheet1 to Find the na...

Open all Excel spreadsheets/fles before running queries
I have a number of spreadsheets which use Ms Query to retrieve data from an Oracle database. I have set it up so that queries run automatically when I open a spreadsheet. In Excel 2003, if I open several such spreadsheets at the same time, Excel will open all spreadsheets first and then run the queries. This means that I can open all the spreadsheets I want to update, get immediate notification if any one of them is in use by someone else, open as read-only if so, and then go off and do something else while all queries update (15-20 minutes in some cases). In Excel 2007 wh...

Finding an event
Hello, I am developing an app that uses a single worksheet to enter data. When user double clicks a button, a new window (in same workbook) opens with a new sheet. My problem is that excel does not seem to have any events for close of window if there are multiple windows in a workbook. Can someone help Peter Peter, That triggers the Workbook_WindowActivate event, you can use that. HTH Bob "Peter Ostermann" wrote in message news:i9m5v8$7bv$02$1@news.t-online.com... Hello, I am developing an app that uses a single worksheet to enter data. When user double clicks a button...

how do i show figures as words?
I'm sure I've seen a spreadsheet where a number was entered into a cell, and there was another cell which must have contained a formula to show that figure in words (eg. for writing a cheque), does anybody out there know how to do this? It's probably really simple!! Cheers Carolyn See http://www.xldynamic.com/source/xld.xlFAQ0004.html -- HTH Bob Phillips "Carolyn" <Carolyn@discussions.microsoft.com> wrote in message news:89E0BBB2-F03E-4383-8BA1-3F0F40AA52AB@microsoft.com... > I'm sure I've seen a spreadsheet where a number was entered into a ce...

Find value in a column and insert rows above
The set up looks like this: ColU ColV ColW ColX Y N N N Y N N N N Y N N N N Y N N N Y N N N Y N N N Y N N N Y Y Columns will always be U through X and will always be sorted in this order. I need to find the first Y in each column and insert 2 rows above that row. On the blank row above the first Y, I need to highlight in yellow and put title in the first cell, such as New, Old, Existing, Deleted. Any help would be greatly appreciated. Thanks for your time, Dee If desired, send your file to my address below. I will only look if: 1. You send a copy of this ...

Where is the graphics selection pointer in excel 2007?
I used to be able to click on the graphics selection tool in office 97 on the left end of the drawing toolbar then click and drag over multiple graphics to select them all. Then I could group them etc. What do i do now? It's to be found in - Insert tab - Illustrations - Shapes - select a shape and insert into w/s and immediately the new drawing tools format tab opens up -- Russell Dawson Excel Student Please hit "Yes" if this post was helpful. "Bruce" wrote: > I used to be able to click on the graphics selection tool in office 97 on the ...

cannot find database
I have an excel spreadsheet that is supposed to update a access db. Whenever I try to save the .xls I get an error stating cannot find db. Even when I open the db with access, I get the error and the db opens anyway?????? This only happens on 2 out of 20 pc's and I cannot figure out why???????? Thanks ...

Sum if Condition is Equal in Range Date and find column
I want to make a sum if Range is a week number and if style is Equal to CONC-92 or CONC-45 Week# 49 Week# 50 CONC-92= 27 CONC-92= 30 CONC-45= 27 CONC-45= 30 Datas are in a pivot table and... Pivot table looks like this: Date CONC-92 CONC-45 CONC-92 CONC-45 12/7 5 5 10 10 12/8 2 2 10 10 12/9 5 5 10 10 12/10 5 5 10 10 please help -- Lorenzo Díaz Cad Technician ...