Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default Loop through a range

I need to check a group of computers for a certian file. The computer
names will be in column A. I got it to work with the below code for
cell A1.

How can I get it to loop through all the rows in column A and return
the Y or N to column B?

(If possible please respond to the group as well as by email as I use
Google and it takes forever to see responses)

-----
Sub checkfile()

mname = "\\" + Range("A1") + "\c$\fred.txt"

If Len(Dir(mname)) 0 Then
Range("B1") = "Y"
Else
Range("B1") = "N"
End If

End Sub
-------

Data:
________________
A B
________________
machine1 Y
machine2 N
machine3 N
machine4 Y
machine5 Y
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Loop through a range

Sub checkfile()
Dim cRows As Long
Dim i As Row

cRows = Cells(Rows.Count,"A").End(xlUp).Row

For i = 1 To cRows
mname = "\\" + Cells(i,"A").Value + "\c$\fred.txt"

If Len(Dir(mname)) 0 Then
Cells(i,"B").Value = "Y"
Else
Cells(i,"B").Value = "N"
End If

Next i

End Sub

--

HTH

RP

"Fred" wrote in message
om...
I need to check a group of computers for a certian file. The computer
names will be in column A. I got it to work with the below code for
cell A1.

How can I get it to loop through all the rows in column A and return
the Y or N to column B?

(If possible please respond to the group as well as by email as I use
Google and it takes forever to see responses)

-----
Sub checkfile()

mname = "\\" + Range("A1") + "\c$\fred.txt"

If Len(Dir(mname)) 0 Then
Range("B1") = "Y"
Else
Range("B1") = "N"
End If

End Sub
-------

Data:
________________
A B
________________
machine1 Y
machine2 N
machine3 N
machine4 Y
machine5 Y



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Loop through a range

Thanks Bob,

But I get an error: "User defined type not defined" with the i As Row
highlighted.

Any ideas?

Fred



*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Loop through a range

Dim i as Long
--
Regards,
Tom Ogilvy

"Fred Gerbig" wrote in message
...
Thanks Bob,

But I get an error: "User defined type not defined" with the i As Row
highlighted.

Any ideas?

Fred



*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Loop through a range

Sorry, type, should be
Dim i As Long

--

HTH

RP

"Fred Gerbig" wrote in message
...
Thanks Bob,

But I get an error: "User defined type not defined" with the i As Row
highlighted.

Any ideas?

Fred



*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Loop through a range

OK, Thanks to everyone I finally got it working. I am not sure if my
Error checking is in the best form but it works.

Thanks again!
Fred
----------
Sub checkfile()
Dim cRows As Long
Dim i As Long

cRows = Cells(Rows.Count, "A").End(xlUp).Row

For i = 1 To cRows

mname = "\\" + Cells(i, "A").Value + "\c$\fred.txt"

If Len(Dir(mname)) 0 Then

Cells(i, "B").Value = "Y"

If Err.Number = 52 Then Cells(i, "B").Value = "Machine Not Found"
On Error Resume Next
Else

Cells(i, "B").Value = "N"

If Err.Number = 52 Then Cells(i, "B").Value = "Machine Not Found"
On Error Resume Next

End If

Next i


End Sub




*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 50
Default Loop through a range

Try this

For iloopCells = 1 to lastcell
mname = "\\" & cells(iloopCells,1) & "\c$\fred.txt"
'*** now do dir test

next iloopCells


Lastcell will be the last cell you want to use. If the row is dynamic try

For iLoopCells = 1 to ActiveSheet.Cells.SpecialCells(xlCellTypeLastCell) .Row


"Fred" wrote:

I need to check a group of computers for a certian file. The computer
names will be in column A. I got it to work with the below code for
cell A1.

How can I get it to loop through all the rows in column A and return
the Y or N to column B?

(If possible please respond to the group as well as by email as I use
Google and it takes forever to see responses)

-----
Sub checkfile()

mname = "\\" + Range("A1") + "\c$\fred.txt"

If Len(Dir(mname)) 0 Then
Range("B1") = "Y"
Else
Range("B1") = "N"
End If

End Sub
-------

Data:
________________
A B
________________
machine1 Y
machine2 N
machine3 N
machine4 Y
machine5 Y

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
reset the range of FOR loop Farooq Sheri Excel Discussion (Misc queries) 1 April 7th 09 08:05 PM
Loop through last cell/row of used range tkraju via OfficeKB.com Excel Discussion (Misc queries) 1 April 4th 09 04:45 PM
using For each loop to populate a range Sean Excel Programming 2 September 30th 04 02:13 PM
Changing range name in loop Jeff Excel Programming 4 July 12th 04 08:32 PM
Increasing a range in a loop ric Excel Programming 4 April 26th 04 07:59 PM


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