Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Using a variable to refer a cell

hi frns

I have a simple question, yet hard to answer for me :) ...

assume that we have a code sth like

sub countcells()

dim n as variant
dim counter as integer

Worksheets("data").Select

For Each n In ActiveSheet.Range("e:e")
If n.Value < 0 Then
counter = counter + 1
End If
Next n

End sub


as u can see we are counting the cells that are not equal to zero on
the column "e" here.

now i gotta use that counter to refer to a cell. it sud be sth like ex:
[a1:a+]

here plus sud be the counter that i define ....

what i wanna do is to copy the cells which have a value. But range may
differ everyday. So i sud count them.

i have searched for all kinds of references but cudn't find a
solution...

any help appreciated frnds ...

thx u all....

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Using a variable to refer a cell

No, you don't need to count them

Worksheets("data").Select
set rng = Range(Cells(1,"E"),Cells(rows.count,"E").End(xlup) )
For Each n In ActiveSheet.Range("e:e")
If n.Value < 0 Then
cells(2,"A").EntireRow.copy Destination:= _
worksheets("NewSheet").Cells(rows.count, _
"A").End(xlup))(2)
End If
Next n

End sub

Hopefully you can adapt this to your problem. If not, post back. If you
wanted to check a condition in a, it would be

Dim rng as Range, n as Range
Worksheets("data").Select
set rng = Range(Cells(1,"E"),Cells(rows.count,"E").End(xlup) )
For Each n In rng
If lcase(n.Offset(0,-4).Value) = "copy" Then
cells(2,"A").EntireRow.copy Destination:= _
worksheets("NewSheet").Cells(rows.count, _
"A").End(xlup))(2)
End If
Next n

End sub

as an example. (to copy all rows where column A contained the single entry:
Copy

--
Regards,
Tom Ogilvy



"jeam" wrote in message
oups.com...
hi frns

I have a simple question, yet hard to answer for me :) ...

assume that we have a code sth like

sub countcells()

dim n as variant
dim counter as integer

Worksheets("data").Select

For Each n In ActiveSheet.Range("e:e")
If n.Value < 0 Then
counter = counter + 1
End If
Next n

End sub


as u can see we are counting the cells that are not equal to zero on
the column "e" here.

now i gotta use that counter to refer to a cell. it sud be sth like ex:
[a1:a+]

here plus sud be the counter that i define ....

what i wanna do is to copy the cells which have a value. But range may
differ everyday. So i sud count them.

i have searched for all kinds of references but cudn't find a
solution...

any help appreciated frnds ...

thx u all....



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
How make hyperlink refer to cell content rather than cell address. Omunene Excel Discussion (Misc queries) 3 March 2nd 06 01:07 AM
variable to refer to "this worksheet"? confused Excel Worksheet Functions 1 June 16th 05 11:51 PM
refer cell using c anupam Excel Programming 2 August 8th 04 03:24 AM
How to refer a Variable across Workbooks ? Prabhu Dev Excel Programming 1 November 27th 03 05:22 AM
Refer to Combo-box using a part + variable Peter[_20_] Excel Programming 3 July 29th 03 08:03 PM


All times are GMT +1. The time now is 04:09 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"