Be Excellent To Each Other

And, you know, party on. Dude.

All times are UTC [ DST ]




Reply to topic  [ 5 posts ] 
Author Message
 Post subject: Excel VBA help
PostPosted: Tue Sep 02, 2008 13:23 
User avatar
Ticket to Ride World Champion

Joined: 18th Apr, 2008
Posts: 11895
Right, I am not particularly good with this stuff.

I am trying to get all the files in a folder into a list in excel, as I am lazy.

I have an array which reads all the files in, and I can output all the files out, the one thing I can't seem to do, is output to a list. Ie, I can't move my activecell to the next in a range, I just overwrite the top cell in the list.

What I thought I could do is:

Code:
Function outputToSheet(listArray As Variant, arraySize As Integer) As Variant
   Dim fileName1 As String
   Dim counter As Integer
   Dim outputRange As Range
     
   counter = 1
   While (counter < arraySize)
   
      fileName1 = listArray(counter)
      Set outputRange = Range(Cells(counter, 1), Cells(arraySize, 1))
      ActiveCell.Value = fileName1 
      ActiveCell = outputRange.Next
      counter = counter + 1
     
   Wend
     


but this doesn't work, I realise I must be missing something fundamental about ranges and cells and selections or something, but any help would be appreciated, Thanks.

_________________
No, it was a giant robot castle!


Top
 Profile  
 
 Post subject: Re: Excel VBA help
PostPosted: Tue Sep 02, 2008 13:26 
SupaMod
User avatar
Commander-in-Cheese

Joined: 30th Mar, 2008
Posts: 49244
Instead of your:

Set outputRange = Range(Cells(counter, 1), Cells(arraySize, 1))
ActiveCell.Value = fileName1
ActiveCell = outputRange.Next

just do:

Cells(counter,1).value = filename1

That is if you're trying to do what I think you're trying to do. If you're doing the output one cell at a time, there's no point bothering with a range.

_________________
GoddessJasmine wrote:
Drunk, pulled Craster's pork, waiting for brdyime story,reading nuts. Xz


Top
 Profile  
 
 Post subject: Re: Excel VBA help
PostPosted: Tue Sep 02, 2008 13:31 
User avatar
Ticket to Ride World Champion

Joined: 18th Apr, 2008
Posts: 11895
:DD That worked nicely!

Okay, why didn't mine work?
[/cheeky]

_________________
No, it was a giant robot castle!


Top
 Profile  
 
 Post subject: Re: Excel VBA help
PostPosted: Tue Sep 02, 2008 13:36 
SupaMod
User avatar
Commander-in-Cheese

Joined: 30th Mar, 2008
Posts: 49244
Because you were re-initialising the range every time you went through the loop.

You could have also tried moving the range initialisation outside the loop:

Set outputRange = Range(Cells(1, 1), Cells(arraySize, 1))
While (counter < arraySize)

fileName1 = listArray(counter)
ActiveCell.Value = fileName1
ActiveCell = outputRange.Next
counter = counter + 1

Wend

Which would probably have worked, although using a range is pretty much unnecessary in this instance.

_________________
GoddessJasmine wrote:
Drunk, pulled Craster's pork, waiting for brdyime story,reading nuts. Xz


Top
 Profile  
 
 Post subject: Re: Excel VBA help
PostPosted: Tue Sep 02, 2008 13:48 
User avatar
Ticket to Ride World Champion

Joined: 18th Apr, 2008
Posts: 11895
Of course*! Okay, brilliant, thanks.

*we need a D'oh Dimlie.

_________________
No, it was a giant robot castle!


Top
 Profile  
 
Display posts from previous:  Sort by  
Reply to topic  [ 5 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search within this thread:
You are using the 'Ted' forum. Bill doesn't really exist any more. Bogus!
Want to help out with the hosting / advertising costs? That's very nice of you.
Are you on a mobile phone? Try http://beex.co.uk/m/
RIP, Owen. RIP, MrC. RIP, Dimmers.

Powered by a very Grim... version of phpBB © 2000, 2002, 2005, 2007 phpBB Group.