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.
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
We will have to see a data sample to know where the date is.
 
Upvote 0

Forum statistics

Threads
1,214,832
Messages
6,121,843
Members
449,051
Latest member
excelquestion515

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top