Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,101
Default date code error, help would be appreciated!

morning,

i having some issues with the below code.
it is supposed to search for the date today minus 12 months, and then copy
all rows in between to a new sheet.
any suggestions would be greatly appreciated!
thanks very much on this very cold and foggy morning!!
mike

Private Sub CommandButton2_Click()
Dim Rng As range
Dim rCell As range
Dim copyRng As range
Dim destRng As range
Dim mydate As Date
Dim sh As Worksheet
Dim CalcMode As Long
Dim arr As Variant
Dim res As Variant
Dim mymonth As Date


mydate = Date
mymonth = Month(mydate)
Set sh = Sheets("Sheet 1")
Set Rng = sh.range("A5:A100")
Set destRng = Sheets("Sheet 2").range("A2")

res = mydate - mymonth

If res = "" Then Exit Sub
arr = Split(res, " ")

With application
CalcMode = .Calculation
.Calculation = xlCalculationManual
.ScreenUpdating = False
End With


For Each rCell In Rng.Cells
If Not IsError(application.Match(rCell.Value, arr, 0)) Then
If copyRng Is Nothing Then
Set copyRng = rCell
Else
Set copyRng = Union(rCell, copyRng)
End If
End If
Next rCell

If Not copyRng Is Nothing Then
copyRng.EntireRow.Copy Destination:=destRng
Else
'nothing found, do nothing
End If

With application
.Calculation = CalcMode
.ScreenUpdating = True
End With
End Sub



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default date code error, help would be appreciated!

Hi Mike,

I believe that the code you are trying to use was originally suggested by me
for a very different purpose: to copy rows containing one of several words
supplied by a user in response to an input box.Certainly, as used, the code
is inappropriate for your current purpose.

In order to assist you, you will need to explain the layout of your data and
your purpose: is the data sorted sequentially; are all rows older than 1
year to be copied; is data to be appended to existing data on the target
sheet, or is the existing data to be overwritten?


---
Regards,
Norman



"mike" wrote in message
...
morning,

i having some issues with the below code.
it is supposed to search for the date today minus 12 months, and then copy
all rows in between to a new sheet.
any suggestions would be greatly appreciated!
thanks very much on this very cold and foggy morning!!
mike

Private Sub CommandButton2_Click()
Dim Rng As range
Dim rCell As range
Dim copyRng As range
Dim destRng As range
Dim mydate As Date
Dim sh As Worksheet
Dim CalcMode As Long
Dim arr As Variant
Dim res As Variant
Dim mymonth As Date


mydate = Date
mymonth = Month(mydate)
Set sh = Sheets("Sheet 1")
Set Rng = sh.range("A5:A100")
Set destRng = Sheets("Sheet 2").range("A2")

res = mydate - mymonth

If res = "" Then Exit Sub
arr = Split(res, " ")

With application
CalcMode = .Calculation
.Calculation = xlCalculationManual
.ScreenUpdating = False
End With


For Each rCell In Rng.Cells
If Not IsError(application.Match(rCell.Value, arr, 0)) Then
If copyRng Is Nothing Then
Set copyRng = rCell
Else
Set copyRng = Union(rCell, copyRng)
End If
End If
Next rCell

If Not copyRng Is Nothing Then
copyRng.EntireRow.Copy Destination:=destRng
Else
'nothing found, do nothing
End If

With application
.Calculation = CalcMode
.ScreenUpdating = True
End With
End Sub





  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,101
Default date code error, help would be appreciated!

Norman,

you are correct.
it is the formula you provided.

basically, i have a sheet.
it contains a number of columns.
my overall purpose of the macro is to.....

search in column A for all dates that are up to and including one year ago
from today's date.
then in column B there is an amount value.
i wish to then add the amounts in column from today back to a year ago today.
if it easier to copy them to a new sheet then this would suffice.
i hope you can help.
thanks

mike
i wish to add the amount value th

"Norman Jones" wrote:

Hi Mike,

I believe that the code you are trying to use was originally suggested by me
for a very different purpose: to copy rows containing one of several words
supplied by a user in response to an input box.Certainly, as used, the code
is inappropriate for your current purpose.

In order to assist you, you will need to explain the layout of your data and
your purpose: is the data sorted sequentially; are all rows older than 1
year to be copied; is data to be appended to existing data on the target
sheet, or is the existing data to be overwritten?


---
Regards,
Norman



"mike" wrote in message
...
morning,

i having some issues with the below code.
it is supposed to search for the date today minus 12 months, and then copy
all rows in between to a new sheet.
any suggestions would be greatly appreciated!
thanks very much on this very cold and foggy morning!!
mike

Private Sub CommandButton2_Click()
Dim Rng As range
Dim rCell As range
Dim copyRng As range
Dim destRng As range
Dim mydate As Date
Dim sh As Worksheet
Dim CalcMode As Long
Dim arr As Variant
Dim res As Variant
Dim mymonth As Date


mydate = Date
mymonth = Month(mydate)
Set sh = Sheets("Sheet 1")
Set Rng = sh.range("A5:A100")
Set destRng = Sheets("Sheet 2").range("A2")

res = mydate - mymonth

If res = "" Then Exit Sub
arr = Split(res, " ")

With application
CalcMode = .Calculation
.Calculation = xlCalculationManual
.ScreenUpdating = False
End With


For Each rCell In Rng.Cells
If Not IsError(application.Match(rCell.Value, arr, 0)) Then
If copyRng Is Nothing Then
Set copyRng = rCell
Else
Set copyRng = Union(rCell, copyRng)
End If
End If
Next rCell

If Not copyRng Is Nothing Then
copyRng.EntireRow.Copy Destination:=destRng
Else
'nothing found, do nothing
End If

With application
.Calculation = CalcMode
.ScreenUpdating = True
End With
End Sub






  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default date code error, help would be appreciated!

Hi Mike,

Are the rows sorted in date order?

Is there additional data in columns C == that should be copied?

If your purpose is to extract information for a one year period, why not use
the autofilter feature to extract all rows between your required dates. You
could then use the SubTotal function to sum the filtered rows, e.g.:

=SUBTOTAL(9,B:B)

---
Regards,
Norman



"mike" wrote in message
...
Norman,

you are correct.
it is the formula you provided.

basically, i have a sheet.
it contains a number of columns.
my overall purpose of the macro is to.....

search in column A for all dates that are up to and including one year ago
from today's date.
then in column B there is an amount value.
i wish to then add the amounts in column from today back to a year ago
today.
if it easier to copy them to a new sheet then this would suffice.
i hope you can help.
thanks

mike
i wish to add the amount value th

"Norman Jones" wrote:

Hi Mike,

I believe that the code you are trying to use was originally suggested by
me
for a very different purpose: to copy rows containing one of several
words
supplied by a user in response to an input box.Certainly, as used, the
code
is inappropriate for your current purpose.

In order to assist you, you will need to explain the layout of your data
and
your purpose: is the data sorted sequentially; are all rows older than 1
year to be copied; is data to be appended to existing data on the target
sheet, or is the existing data to be overwritten?


---
Regards,
Norman



"mike" wrote in message
...
morning,

i having some issues with the below code.
it is supposed to search for the date today minus 12 months, and then
copy
all rows in between to a new sheet.
any suggestions would be greatly appreciated!
thanks very much on this very cold and foggy morning!!
mike

Private Sub CommandButton2_Click()
Dim Rng As range
Dim rCell As range
Dim copyRng As range
Dim destRng As range
Dim mydate As Date
Dim sh As Worksheet
Dim CalcMode As Long
Dim arr As Variant
Dim res As Variant
Dim mymonth As Date


mydate = Date
mymonth = Month(mydate)
Set sh = Sheets("Sheet 1")
Set Rng = sh.range("A5:A100")
Set destRng = Sheets("Sheet 2").range("A2")

res = mydate - mymonth

If res = "" Then Exit Sub
arr = Split(res, " ")

With application
CalcMode = .Calculation
.Calculation = xlCalculationManual
.ScreenUpdating = False
End With


For Each rCell In Rng.Cells
If Not IsError(application.Match(rCell.Value, arr, 0)) Then
If copyRng Is Nothing Then
Set copyRng = rCell
Else
Set copyRng = Union(rCell, copyRng)
End If
End If
Next rCell

If Not copyRng Is Nothing Then
copyRng.EntireRow.Copy Destination:=destRng
Else
'nothing found, do nothing
End If

With application
.Calculation = CalcMode
.ScreenUpdating = True
End With
End Sub








  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,101
Default date code error, help would be appreciated!

Norman can Autofilter be used in macros?

There is data in other columns, but i need only 2 other columns at most.
the rows are sorted by date order but are not sequential, eg the dates will
run in month order, but days may be skipped or doubled up, where there were
no entries for some days or more on another day.
i am trying to format it in a macro, because i have wrote something similar,
using your help before, which looks for a certain word in column a then
copies all information relating to that word, ie all rows that contain the
word, and the relevant information in those rows, to a new sheet, which is
then automatically mailed to someone.

what i am trying to do now is collate the number values to complile reports
and email them automatically. this is just the start, my manager also asked
if it would be possible to analyse the amounts on a quarter on quarter basis
to see if there is a reduction in frequency of the values.

i hope you can help, i think im getting a bit out of my depth!! might have
to go and buy a textbook for this stuff at lunch!!!

thanks again

mike

"Norman Jones" wrote:

Hi Mike,

Are the rows sorted in date order?

Is there additional data in columns C == that should be copied?

If your purpose is to extract information for a one year period, why not use
the autofilter feature to extract all rows between your required dates. You
could then use the SubTotal function to sum the filtered rows, e.g.:

=SUBTOTAL(9,B:B)

---
Regards,
Norman



"mike" wrote in message
...
Norman,

you are correct.
it is the formula you provided.

basically, i have a sheet.
it contains a number of columns.
my overall purpose of the macro is to.....

search in column A for all dates that are up to and including one year ago
from today's date.
then in column B there is an amount value.
i wish to then add the amounts in column from today back to a year ago
today.
if it easier to copy them to a new sheet then this would suffice.
i hope you can help.
thanks

mike
i wish to add the amount value th

"Norman Jones" wrote:

Hi Mike,

I believe that the code you are trying to use was originally suggested by
me
for a very different purpose: to copy rows containing one of several
words
supplied by a user in response to an input box.Certainly, as used, the
code
is inappropriate for your current purpose.

In order to assist you, you will need to explain the layout of your data
and
your purpose: is the data sorted sequentially; are all rows older than 1
year to be copied; is data to be appended to existing data on the target
sheet, or is the existing data to be overwritten?


---
Regards,
Norman



"mike" wrote in message
...
morning,

i having some issues with the below code.
it is supposed to search for the date today minus 12 months, and then
copy
all rows in between to a new sheet.
any suggestions would be greatly appreciated!
thanks very much on this very cold and foggy morning!!
mike

Private Sub CommandButton2_Click()
Dim Rng As range
Dim rCell As range
Dim copyRng As range
Dim destRng As range
Dim mydate As Date
Dim sh As Worksheet
Dim CalcMode As Long
Dim arr As Variant
Dim res As Variant
Dim mymonth As Date


mydate = Date
mymonth = Month(mydate)
Set sh = Sheets("Sheet 1")
Set Rng = sh.range("A5:A100")
Set destRng = Sheets("Sheet 2").range("A2")

res = mydate - mymonth

If res = "" Then Exit Sub
arr = Split(res, " ")

With application
CalcMode = .Calculation
.Calculation = xlCalculationManual
.ScreenUpdating = False
End With


For Each rCell In Rng.Cells
If Not IsError(application.Match(rCell.Value, arr, 0)) Then
If copyRng Is Nothing Then
Set copyRng = rCell
Else
Set copyRng = Union(rCell, copyRng)
End If
End If
Next rCell

If Not copyRng Is Nothing Then
copyRng.EntireRow.Copy Destination:=destRng
Else
'nothing found, do nothing
End If

With application
.Calculation = CalcMode
.ScreenUpdating = True
End With
End Sub











  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default date code error, help would be appreciated!

Hi Mike,

Norman can Autofilter be used in macros?


Certainly!

Turn on the macro recorder, perform the required operations manually. This
will provide you with base code that can be edited to improve efficiency and
render it appropriate for general application.

If you require any assistance with such editing, post back with specifics.

From your description, I think that the autofilter will best meet your
requirements.

---
Regards,
Norman



"mike" wrote in message
...
Norman can Autofilter be used in macros?

There is data in other columns, but i need only 2 other columns at most.
the rows are sorted by date order but are not sequential, eg the dates
will
run in month order, but days may be skipped or doubled up, where there
were
no entries for some days or more on another day.
i am trying to format it in a macro, because i have wrote something
similar,
using your help before, which looks for a certain word in column a then
copies all information relating to that word, ie all rows that contain the
word, and the relevant information in those rows, to a new sheet, which is
then automatically mailed to someone.

what i am trying to do now is collate the number values to complile
reports
and email them automatically. this is just the start, my manager also
asked
if it would be possible to analyse the amounts on a quarter on quarter
basis
to see if there is a reduction in frequency of the values.

i hope you can help, i think im getting a bit out of my depth!! might have
to go and buy a textbook for this stuff at lunch!!!

thanks again

mike

"Norman Jones" wrote:

Hi Mike,

Are the rows sorted in date order?

Is there additional data in columns C == that should be copied?

If your purpose is to extract information for a one year period, why not
use
the autofilter feature to extract all rows between your required dates.
You
could then use the SubTotal function to sum the filtered rows, e.g.:

=SUBTOTAL(9,B:B)

---
Regards,
Norman



"mike" wrote in message
...
Norman,

you are correct.
it is the formula you provided.

basically, i have a sheet.
it contains a number of columns.
my overall purpose of the macro is to.....

search in column A for all dates that are up to and including one year
ago
from today's date.
then in column B there is an amount value.
i wish to then add the amounts in column from today back to a year ago
today.
if it easier to copy them to a new sheet then this would suffice.
i hope you can help.
thanks

mike
i wish to add the amount value th

"Norman Jones" wrote:

Hi Mike,

I believe that the code you are trying to use was originally suggested
by
me
for a very different purpose: to copy rows containing one of several
words
supplied by a user in response to an input box.Certainly, as used, the
code
is inappropriate for your current purpose.

In order to assist you, you will need to explain the layout of your
data
and
your purpose: is the data sorted sequentially; are all rows older than
1
year to be copied; is data to be appended to existing data on the
target
sheet, or is the existing data to be overwritten?


---
Regards,
Norman



"mike" wrote in message
...
morning,

i having some issues with the below code.
it is supposed to search for the date today minus 12 months, and
then
copy
all rows in between to a new sheet.
any suggestions would be greatly appreciated!
thanks very much on this very cold and foggy morning!!
mike

Private Sub CommandButton2_Click()
Dim Rng As range
Dim rCell As range
Dim copyRng As range
Dim destRng As range
Dim mydate As Date
Dim sh As Worksheet
Dim CalcMode As Long
Dim arr As Variant
Dim res As Variant
Dim mymonth As Date


mydate = Date
mymonth = Month(mydate)
Set sh = Sheets("Sheet 1")
Set Rng = sh.range("A5:A100")
Set destRng = Sheets("Sheet 2").range("A2")

res = mydate - mymonth

If res = "" Then Exit Sub
arr = Split(res, " ")

With application
CalcMode = .Calculation
.Calculation = xlCalculationManual
.ScreenUpdating = False
End With


For Each rCell In Rng.Cells
If Not IsError(application.Match(rCell.Value, arr, 0)) Then
If copyRng Is Nothing Then
Set copyRng = rCell
Else
Set copyRng = Union(rCell, copyRng)
End If
End If
Next rCell

If Not copyRng Is Nothing Then
copyRng.EntireRow.Copy Destination:=destRng
Else
'nothing found, do nothing
End If

With application
.Calculation = CalcMode
.ScreenUpdating = True
End With
End Sub











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
Any Help Appreciated CALM1 Excel Worksheet Functions 3 June 17th 11 06:59 AM
Help is much appreciated for- V Excel Discussion (Misc queries) 10 May 28th 09 12:16 AM
Help would be much appreciated! Daptin Excel Worksheet Functions 2 November 24th 06 03:50 AM
Any help much appreciated Ryk Excel Discussion (Misc queries) 0 July 31st 06 04:59 PM
Code Error - Run Time Error 5 (Disable Cut, Copy & Paste) Tim[_36_] Excel Programming 4 April 23rd 04 02:53 AM


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