Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default For...Next Question

How do I get the following to loop until the end of a sheet with up to 200
entries in column A starting at row 3 and changing the range as it goes
through the loop. I'm new to this and any help much appreciated.

Sub test()

Dim i, j As Integer
Dim INS As String

i = 0: j -0

If ActiveSheet.Range("j3").Value < Empty Then i = i + 1: j = 1
If ActiveSheet.Range("k3").Value < Empty Then i = i - 1
If ActiveSheet.Range("l3").Value < Empty Then i = i + 1: j = 1
If ActiveSheet.Range("m3").Value < Empty Then i = 1 - 1

If j = 0 Then INS = ("N"): GoTo E
If i = 0 Then INS = ("C"): GoTo E
If i 0 Then INS = ("A")

E:
ActiveSheet.Range("n3") = INS

End Sub


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default For...Next Question

Sub test()

Dim i as Long, j As Long
Dim INS As String
Dim k as long, lastrow as Long
lastrow = cells(rows.count,1).End(xlup)


for k = 1 to lastrow - 2

i = 0: j =0


If ActiveSheet.Range("j3")(k).Value < Empty Then i = i + 1: j = 1
If ActiveSheet.Range("k3")(k).Value < Empty Then i = i - 1
If ActiveSheet.Range("l3")(k).Value < Empty Then i = i + 1: j = 1
If ActiveSheet.Range("m3")(k).Value < Empty Then i = 1 - 1

If j = 0 Then
INS = "N"
elseIf i = 0 Then
INS = "C"
elseIf i 0 Then
INS = "A"
End if
ActiveSheet.Range("n3")(k).Value = INS

Next k
End Sub

I don't know what you are doing, so I don't know if i and j should be set to
zero for each row. As written they are. If they should be initialized only
at the start, then move that line above the For i = line.

--
Regards,
Tom Ogilvy

"br0ke" wrote in message
...
How do I get the following to loop until the end of a sheet with up to 200
entries in column A starting at row 3 and changing the range as it goes
through the loop. I'm new to this and any help much appreciated.

Sub test()

Dim i, j As Integer
Dim INS As String

i = 0: j -0

If ActiveSheet.Range("j3").Value < Empty Then i = i + 1: j = 1
If ActiveSheet.Range("k3").Value < Empty Then i = i - 1
If ActiveSheet.Range("l3").Value < Empty Then i = i + 1: j = 1
If ActiveSheet.Range("m3").Value < Empty Then i = 1 - 1

If j = 0 Then INS = ("N"): GoTo E
If i = 0 Then INS = ("C"): GoTo E
If i 0 Then INS = ("A")

E:
ActiveSheet.Range("n3") = INS

End Sub




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default For...Next Question

I had to change to

lastrow = worksheets("Sheet1").usedrange.rows.count

but everthing else worked well. Thanks....
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default For...Next Question

since you said:
of a sheet with up to 200

entries in column A starting at row 3

Why wouldn't column A be a sufficient indicator of the lastrow.

Nonetheless, glad you succeeded.

--
Regards,
Tom Ogilvy

"br0ke" wrote in message
...
I had to change to

lastrow = worksheets("Sheet1").usedrange.rows.count

but everthing else worked well. Thanks....



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
Excel 2007 Macro/VB Question DDE Question MadDog22 Excel Worksheet Functions 1 March 10th 10 01:47 AM
where can I see my question and answer? Yesterday I ask a question IP Excel Discussion (Misc queries) 2 May 10th 08 04:08 PM
question boSS Excel Discussion (Misc queries) 1 October 30th 06 11:03 PM
Newbie Question - Subtraction Formula Question [email protected] Excel Discussion (Misc queries) 3 May 5th 06 05:50 PM
The question is an excel question that I need to figure out howto do in excel. Terry Excel Worksheet Functions 3 January 23rd 06 06:22 PM


All times are GMT +1. The time now is 07:32 AM.

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

About Us

"It's about Microsoft Excel"