Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 58
Default Macro to insert data behind a certain date.

Hi Barb,

Thanks for that. I came up with a solution to the non-zero values
problem last night, but I'm still stumped by the insert in the right
chronological order problem.

Looking through some of my other spreadsheets I found I'd already
cracked the nil values one for a macro I did a couple of years ago to
amend the selected data for a chart, so I wouldn't chart zero series.
With a bit of modification it worked here.

The following function takes a specified range and returns a range
specifying only the rows where the numerical fields (columns 7 to 9)
aren't all zero. This range can be copied and pasted to the target
cell, but I'm still stumped by trying to figure out how to code for
the target row.

Pasting at the end of the data sheet and then running a sort would
work but wouldn't be ideal as occasionally there are pieces of data
which need to be in a specific order other than an exact chronolonical
ordering. (They need to be in the same order as the statement the
data has been copied from, to make it easier to check against the
statement during audit.)

Travis

Function NonZeroCommissions(inputrange As Range) As Range

Dim DownCounter, AcrossCounter, NumberOfRows As Integer
Dim temprange, copyable, upperleft As Range


NumberOfRows = inputrange.Rows.Count


Set upperleft = inputrange.Resize(1, 1)

' Find the first series which isn't all zeros, and name its range
"copyable"

For DownCounter = 0 To NumberOfRows

For AcrossCounter = 7 To 9

If Not upperleft.Offset(DownCounter, AcrossCounter).Value = 0 Then

Set copyable = Range(upperleft.Offset(DownCounter, 0).Address &
":" & upperleft.Offset(DownCounter, 21).Address)

Exit For

End If

Next AcrossCounter

Next DownCounter

' Now build up the rest of the range by adding additional ranges which
also have non zeros

For DownCounter = 0 To NumberOfRows

For AcrossCounter = 7 To 9

If Not upperleft.Offset(DownCounter, AcrossCounter).Value = 0
Then

Set temprange = Range(upperleft.Offset(DownCounter, 0).Address
& ":" & upperleft.Offset(DownCounter, 21).Address)
Set copyable = Union(copyable, temprange)

AcrossCounter = 1

Exit For

End If

Next AcrossCounter


Next DownCounter

Set NonZeroCommissions = copyable

End Function
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
Insert date in macro George Gee New Users to Excel 12 April 17th 06 05:44 AM
Insert Date that Macro runs jhahes[_16_] Excel Programming 7 August 5th 05 11:49 PM
Insert Date that Macro runs bhofsetz[_108_] Excel Programming 0 July 8th 05 07:24 PM
How do I insert the date using a macro tara0801 Excel Discussion (Misc queries) 4 February 10th 05 09:09 PM
Insert Row using Macro, Group By Date JRW[_2_] Excel Programming 3 September 5th 03 05:03 PM


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