VBA Code for transfer of data to a new exce sheet based on condition

deva123

New Member
Joined
Aug 19, 2014
Messages
5
Dear friends,
I have <acronym title="visual basic for applications">VBA</acronym> code for transfer of data to another sheet. it works fine. but if the command button is pressed two times, it transfer the data for two times.

I need <acronym title="visual basic for applications">VBA</acronym> code which will transfer data to another sheet based on "date" (every Month end date) criteria,
if the criteria is met, it should replace the data.
if the criteria is not met, it should transfer the data to the first empty row.
totally either the data either should be replaced or transferred to empty row.

the code for transferring data to another sheet is attached herewith

Sub TransferToAnotherSheet_Click()
Dim smallrng As Range, DestRange As Range
Dim DestSheet As Worksheet, Lr As Long
Dim SourceRange As Range, i As Integer

With Application
.ScreenUpdating = False
.EnableEvents = False
End With

'fill in the Source Sheet and range
Set SourceRange = Sheets("Master").Range("A9:V10500")

'Fill in the destination sheet and call the LastRow
'function to find the last row
Set DestSheet = Sheets("FinalMaster")
Lr = DestSheet.Cells(Rows.Count, "A").End(xlUp).Row
i = 1

For Each smallrng In SourceRange.Areas

'We make DestRange the same size as smallrng and use the
'Value property to give DestRange the same values
With smallrng
Set DestRange = DestSheet.Cells(Lr + 1, i) _
.Resize(.Rows.Count, .Columns.Count)
End With
DestRange.Value = smallrng.Value
i = i + smallrng.Columns.Count
MsgBox "The data has been successfully copied."

Next smallrng

With Application
.ScreenUpdating = True
.EnableEvents = True
End With

End Sub

I need a new <acronym title="visual basic for applications">VBA</acronym> code which will meet the both the criteria.

Thanks in advance.
 

Some videos you may like

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.

Warship

Well-known Member
Joined
Jul 17, 2007
Messages
1,051
We will have to see a data sample to know where the date is.
 

Watch MrExcel Video

Forum statistics

Threads
1,109,436
Messages
5,528,758
Members
409,834
Latest member
vexceled

This Week's Hot Topics

  • Change military grades into rank
    Afternoon all Need help with formula that will change military rank (i.e. 1, 2, 3 into Amn, A1C, SrA). Running IF formula that does not work...
  • VBA COUNTIF SOLUTION
    Hi The following are the errors spread across the several columns from E to Q ie. 13 columns across several sheets with more than 500 rows per...
  • INSERT ROW WITH SPECIFIS TEXT IN A COLUMN
    Hi All! How can identify that that the row to be inserted has to be inserted before 1st row with specific text in column F. If I record the...
  • Auto-Create a monthly Sign in sheet for preschool students
    The image below is what each page looks like. Above is space for the "Child Name" "Month" "Class" School days are obviously Monday-Friday but...
  • VBA vlookup multiple results
    Hi folks, Hopefully someone out there can help. I have a list to vlookup which works (ish). the lookup only picks up the first instance of the...
  • Extract values for earliest/latest times
    I am trying to put together a formula to get the earliest start time, the latest end time from column A for each person in Column B-F without the...
Top