Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 96
Default Can I loop this?

.....or is there a better way to write this?


Private Sub CB1_Click()



With ThisWorkbook.Worksheets("February")
.Range("B5").Value = Worksheets("020110").Range("B5").Value +
Worksheets("020210").Range("B5").Value


End With
End Sub

The Worksheets go from "020110" to "022710"
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Can I loop this?


Dates are number with the first day Jan 1, 1900 and each day equal 1.
this code should work


Private Sub CB1_Click()

StartDate = DateValue("020110")
EndDate = DateValue("022710")


With ThisWorkbook.Worksheets("February")
For MyDate = StartDate To EndDate
Yesterday = Format(MyDate - 1, "MMDDYY")
DateStr = Format(MyDate, "MMDDYY")

.Range("B5").Value = _
Worksheets(Yesterday).Range("B5").Value + _
Worksheets(DateStr).Range("B5").Value
Next MyDate
End With
End Sub


--
joel
------------------------------------------------------------------------
joel's Profile: 229
View this thread: http://www.thecodecage.com/forumz/sh...d.php?t=193373

http://www.thecodecage.com/forumz

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 269
Default Can I loop this?

You could loop it something like this

For A=1 to 27
If A<10 Then
tgtname="020" & Cstr(A) & "10"
Else
tgtname="02" & Cstr(A) & "10"
End If

Sheets("February").Range("B5") = Sheets("February").Range("B5") +
Sheets(tgtname).Range("B5")

Next A
--
If this helps, please remember to click yes.


"Qaspec" wrote:

....or is there a better way to write this?


Private Sub CB1_Click()



With ThisWorkbook.Worksheets("February")
.Range("B5").Value = Worksheets("020110").Range("B5").Value +
Worksheets("020210").Range("B5").Value


End With
End Sub

The Worksheets go from "020110" to "022710"

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 96
Default Can I loop this?

Joel

I get a Type Mismatch Error when i try to execute.

The highlight shows on -

StartDate = DateValue("020110")


"joel" wrote:


Dates are number with the first day Jan 1, 1900 and each day equal 1.
this code should work


Private Sub CB1_Click()

StartDate = DateValue("020110")
EndDate = DateValue("022710")


With ThisWorkbook.Worksheets("February")
For MyDate = StartDate To EndDate
Yesterday = Format(MyDate - 1, "MMDDYY")
DateStr = Format(MyDate, "MMDDYY")

.Range("B5").Value = _
Worksheets(Yesterday).Range("B5").Value + _
Worksheets(DateStr).Range("B5").Value
Next MyDate
End With
End Sub


--
joel
------------------------------------------------------------------------
joel's Profile: 229
View this thread: http://www.thecodecage.com/forumz/sh...d.php?t=193373

http://www.thecodecage.com/forumz

.

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 563
Default Can I loop this?

So did I. Maybe because we both use universal (not USA) date format
I replaced the code with
StartDate = DateValue("Feb 1 2010")
EndDate = DateValue("Feb 27 2010")
and the error when away
best wishes
--
Bernard Liengme
Microsoft Excel MVP
http://people.stfx.ca/bliengme

"Qaspec" wrote in message
...
Joel

I get a Type Mismatch Error when i try to execute.

The highlight shows on -

StartDate = DateValue("020110")


"joel" wrote:


Dates are number with the first day Jan 1, 1900 and each day equal 1.
this code should work


Private Sub CB1_Click()

StartDate = DateValue("020110")
EndDate = DateValue("022710")


With ThisWorkbook.Worksheets("February")
For MyDate = StartDate To EndDate
Yesterday = Format(MyDate - 1, "MMDDYY")
DateStr = Format(MyDate, "MMDDYY")

.Range("B5").Value = _
Worksheets(Yesterday).Range("B5").Value + _
Worksheets(DateStr).Range("B5").Value
Next MyDate
End With
End Sub


--
joel
------------------------------------------------------------------------
joel's Profile: 229
View this thread:
http://www.thecodecage.com/forumz/sh...d.php?t=193373

http://www.thecodecage.com/forumz

.



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Can I loop this?


sorry, Datevalue only takes string values that VBA recognizes as valid
dates. VBA won't recognize 020110, but wil recognize a lot of different
strings like
2/1/2010 and any other string values that a worksheet will accept.

I also noticed I did move down the rows for each entry

Private Sub CB1_Click()

StartDate = DateValue("Feb 1 2010")
EndDate = DateValue("Feb 27 2010")

With ThisWorkbook.Worksheets("February")
RowCount = 5
For MyDate = StartDate To EndDate
Yesterday = Format(MyDate - 1, "MMDDYY")
DateStr = Format(MyDate, "MMDDYY")

.Range("B" & RowCount).Value = _
Worksheets(Yesterday).Range("B" & RowCount).Value + _
Worksheets(DateStr).Range("B" & RowCount).Value
RowCount = rowcount + 1
Next MyDate
End With
End Sub


--
joel
------------------------------------------------------------------------
joel's Profile: 229
View this thread: http://www.thecodecage.com/forumz/sh...d.php?t=193373

http://www.thecodecage.com/forumz

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Can I loop this?

I would drop the DateValue() stuff and just use dateserial:

StartDate = DateValue("020110")
becomes
StartDate = Dateserial(2010,2,1) 'ymd order

And I'd declare my variables, too:

Dim StartDate as Date





Qaspec wrote:

Joel

I get a Type Mismatch Error when i try to execute.

The highlight shows on -

StartDate = DateValue("020110")

"joel" wrote:


Dates are number with the first day Jan 1, 1900 and each day equal 1.
this code should work


Private Sub CB1_Click()

StartDate = DateValue("020110")
EndDate = DateValue("022710")


With ThisWorkbook.Worksheets("February")
For MyDate = StartDate To EndDate
Yesterday = Format(MyDate - 1, "MMDDYY")
DateStr = Format(MyDate, "MMDDYY")

.Range("B5").Value = _
Worksheets(Yesterday).Range("B5").Value + _
Worksheets(DateStr).Range("B5").Value
Next MyDate
End With
End Sub


--
joel
------------------------------------------------------------------------
joel's Profile: 229
View this thread: http://www.thecodecage.com/forumz/sh...d.php?t=193373

http://www.thecodecage.com/forumz

.


--

Dave Peterson
  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Can I loop this?


Dave: I agree that using Dateserial is a good idea if you are using the
workbook internationally, but if you are only using the workbook in one
coutry like the USA then Datavalue will always work.


--
joel
------------------------------------------------------------------------
joel's Profile: 229
View this thread: http://www.thecodecage.com/forumz/sh...d.php?t=193373

http://www.thecodecage.com/forumz

  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Can I loop this?

I still don't think it's a good idea.

joel wrote:

Dave: I agree that using Dateserial is a good idea if you are using the
workbook internationally, but if you are only using the workbook in one
coutry like the USA then Datavalue will always work.

--
joel
------------------------------------------------------------------------
joel's Profile: 229
View this thread: http://www.thecodecage.com/forumz/sh...d.php?t=193373

http://www.thecodecage.com/forumz


--

Dave Peterson
  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Can I loop this?


I don't like when I get a posted worksheet data from England that have
to fix the dates before I can paste data into a worksheet, but there
isn't much I can do about the problem. It would be nice if could format
the column on the worksheet that you are putting in a foreign date and
excel would automatically do the conversion. Microsoft doesn't have any
solution to this problem.


--
joel
------------------------------------------------------------------------
joel's Profile: 229
View this thread: http://www.thecodecage.com/forumz/sh...d.php?t=193373

http://www.thecodecage.com/forumz



  #11   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Can I loop this?

And it surely makes it easier to understand what 01/02/03 means when it's
formatted in an umabiguous date format.

I'm still learning that lesson <vbg.



joel wrote:

I don't like when I get a posted worksheet data from England that have
to fix the dates before I can paste data into a worksheet, but there
isn't much I can do about the problem. It would be nice if could format
the column on the worksheet that you are putting in a foreign date and
excel would automatically do the conversion. Microsoft doesn't have any
solution to this problem.

--
joel
------------------------------------------------------------------------
joel's Profile: 229
View this thread: http://www.thecodecage.com/forumz/sh...d.php?t=193373

http://www.thecodecage.com/forumz


--

Dave Peterson
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
returning back to loop check condition without completing the loop ashish128 Excel Programming 13 April 3rd 08 12:53 PM
Loop to Filter, Name Sheets. If Blank, Exit Loop ryguy7272 Excel Programming 3 February 5th 08 03:41 PM
Naming Worksheets - Loop within a loop issue klysell Excel Programming 5 March 29th 07 05:48 AM
Advancing outer Loop Based on criteria of inner loop ExcelMonkey Excel Programming 1 August 15th 05 05:23 PM
Problem adding charts using Do-Loop Until loop Chris Bromley[_2_] Excel Programming 2 May 23rd 05 01:31 PM


All times are GMT +1. The time now is 02:46 PM.

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"