Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Meaning of simple code

Can I know wat does the following statement mean?

For i = 161 To 301
If Trim(Cells(i, 7)) = "1" Then
Rows(i).Hidden = True
ElseIf Trim(Cells(i, 7)) = "True" Then
Rows(i).Hidden = True
End If
If Trim(Cells(i, 7)) = "0" Then
Rows(i).Hidden = False
End If
Next i

Basically, I dunno the meaning of Trim(Cells(i,7))
Can someone pls explain

--
Message posted from http://www.ExcelForum.com

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 13
Default Meaning of simple code

TRIM: Remove both leading and trailing spaces.
CELLS(A,B): Cell at row A, column B.

It's all in the vba help file.

Cheers


"courtesio99" wrote in message
...
Can I know wat does the following statement mean?

For i = 161 To 301
If Trim(Cells(i, 7)) = "1" Then
Rows(i).Hidden = True
ElseIf Trim(Cells(i, 7)) = "True" Then
Rows(i).Hidden = True
End If
If Trim(Cells(i, 7)) = "0" Then
Rows(i).Hidden = False
End If
Next i

Basically, I dunno the meaning of Trim(Cells(i,7))
Can someone pls explain?


---
Message posted from http://www.ExcelForum.com/



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 218
Default Meaning of simple code

The Cells method is used to specify a cell address. The
first argument in the Cells method specifies the cell row
number. The second argument specifies the column number.
For example, Cells(4, 5) simply refers to Cell E4.

Trim (in the form that is used here) is a function used to
remove both leading and trailing blank spaces if they
exist in a cell value. This is usually done to correct
for accidental inclusion of blank space(s) at the
beginning and/or end of an entry. Trim(Cells(4, 5))
removes any leading and trailing blank space(s) if they
exist in Cell E4. Internal blank spaces (e.g. between
words) are not removed by this method.

The code "For i = 161 To 301" followed at the end by "Next
i" is a block code structure that repeatedly runs the code
contained between these two statements for the specified
number of times - in this case 141 times. The "i"
variable starts with an initial value of 161 and is
incremented by 1 for each loop until i has a value of
301. Cells(i, 7) therefore refers first to Cell G161,
then Cell G162 . . . and finally Cell G301. The code in
this manner sequentially references each cell in the range
G161 to G301.

A summary of the code follows:
1) Loops through each cell in the range G161 to G301.
2) For each cell in the above range it first removes any
leading and trailing blank spaces if they exist.
3) After removing blank spaces if they exist, the code
checks to see if the cell value equals "1" (in text form
as opposed to numeric). If found, the row that the cell
is in is therefore hidden.
4) It also checks if the cell value is equal to "True" and
if so also hides the row that the cell is in.
5) Finally, it checks if the cell value is equal to "0"
and if so, in contrast, unhides the row that the cell is
in.

Of note, the values "1" and "0" are expressed as text as
opposed to numeric. This is possibly an error. The code
uses two nested block If statements when only one was
necessary and therefore possibly reflects lack of
experience. Just a guess on my part.

Hope it helps.

Regards,
Greg


-----Original Message-----
Can I know wat does the following statement mean?

For i = 161 To 301
If Trim(Cells(i, 7)) = "1" Then
Rows(i).Hidden = True
ElseIf Trim(Cells(i, 7)) = "True" Then
Rows(i).Hidden = True
End If
If Trim(Cells(i, 7)) = "0" Then
Rows(i).Hidden = False
End If
Next i

Basically, I dunno the meaning of Trim(Cells(i,7))
Can someone pls explain?


---
Message posted from http://www.ExcelForum.com/

.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with some simple code Angeline Excel Discussion (Misc queries) 4 October 12th 06 09:06 AM
Simple Code, I think... [email protected] Excel Worksheet Functions 1 August 2nd 06 08:09 PM
Some simple code WiReLaD Excel Programming 1 October 30th 03 07:11 PM
Simple For Each Next code Keith Willshaw Excel Programming 0 July 28th 03 12:57 PM
Simple For Each Next code Marek S. Excel Programming 0 July 28th 03 12:34 PM


All times are GMT +1. The time now is 06:12 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"