View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Joseph[_55_] Joseph[_55_] is offline
external usenet poster
 
Posts: 1
Default Whats wrong with this code?


Whoa, easy there JE McGimpsey. Im quite new to this scene, and while
appreciate your comments are polite they are also quite pointed. S
please, take it easy on a newcomer. It would have been alot easier t
say "Can you give me more of an idea of whats wrong please with a mayb
a few more detailed pointers on the problem you're having?", rather tha
launching into a whole diatribe about the ins and outs of how to conduc
yourself in a troubleshooting forum. So, that said, after reading you
rather humiliating and almost insulting reply, here are some mor
pointers on the trouble I am having. I don't expect you to help an
wouldn't particularly care if you didn't as you obviously would rathe
pick a newcomer to pieces than help out, so for the benefit of anyon
else, apologies for the original vagaries, and here is a more detaile
look at the problem I have.

I have a userform in the workbook, with two textboxes and a comman
button. Textbox1 contains the starting date range, while textbox
contains the ending date range. As you can see there is some strin
manipulation there, but this is just to make sure the users ar
inputting correct date ranges (this all works fine). I have a list o
usernames in one sheet down a column. I have basically said that whil
the length of the activecell is greater than zero, keep looking fo
files containing a file extension of *.csv, a date value between th
values of textbox1 and textbox2 as well as the username in the activ
cell. Hence, the name of the file is constructed like so:

activecell.value & " " & textbox1.value & " " & "activitylog.csv"

The code loops through the list of usernames constantly using th
offset command until the variable storing date1 is equal to th
variable storing date2. The files do all open without any problem
however it seems certain date ranges won't work. A formula is the
created using this piece of code:

sheets("reports").Select
Dim MyCell As Range
Dim Wb As Workbook
Dim MyFormula As String
Dim mystr

Set MyCell = ThisWorkbook.sheets("reports").Range("B2")

For Each Wb In Workbooks

If Wb.Name < ThisWorkbook.Name Then

MyFormula = MyFormula & "'" & Wb.Name & "'" & "!R2C2" & ","

End If

Next Wb

MyCell.FormulaR1C1 = "=SUM(" & Left(MyFormula, Len(MyFormula) - 1)
")"


However this code doesn't always work. The cell it is supposed to en
up in is B2, but when I look at B2 it is empty. Could this be becaus
of the size of the formula Im generating? The sub titled "finds()" i
geared to find all instances of the $ symbol, but obviously if th
formula isn't there it won't find anything. It then proceeds t
autofill the range I ask it to, but there is no formula to autofil
with.

Regard

--
Josep

-----------------------------------------------------------------------
Joseph's Profile: http://www.excelforum.com/member.php...nfo&userid=563
View this thread: http://www.excelforum.com/showthread.php?threadid=32057