VBA code needed to copy data

sooshil

Board Regular
Joined
Feb 21, 2013
Messages
104
Office Version
  1. 365
Platform
  1. Windows
  2. Mobile
Hi all

I have some data that ranges A28:J37. I don't always have all that range full.
Sometimes I will have A28:J30, sometimes A28:J34 and so on.
The column A will be filled with "" upto A37 when there are no data.

Now my requirement is I need a macro that copies only that range A28 to Jx where x is the last row that has some value other than "" in column A.
I just need to check column A not having "". And, I need that copied values to be pasted as values in another sheet.

for example,

column A
abc(A28)
def(A29)
ghi(A30)
""
""
""
""
and so on upto A37
Now, the macro should copy A28:J30 and paste as values in another sheet.
Next time, if A31 also has values other than "", then it should copy A28:J31 and paste as values in another sheet.
I can configure the destination sheet in the code.

Thank you.
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Does col A have a formula that returns "", or is the "" hard values?
 
Upvote 0
Change the paste sheet and range to suit:
Code:
Sub sooshil()
'assumes this code is run from Sheet1 and paste is to sheet2
Dim R As Range, lR As Long
Set R = Range("A28:J37")
lR = Range("A28:J37").Columns(1).Find("*", LookIn:=xlValues, searchdirection:=xlPrevious).Row
Range("A28:J" & lR).Copy
With Sheets("Sheet2")
    .Range("A1").PasteSpecial Paste:=xlPasteValues
End With
Application.CutCopyMode = False
End Sub
 
Upvote 0
In that case try JoeMo's code :)
 
Upvote 0
Change the paste sheet and range to suit:
Code:
Sub sooshil()
'assumes this code is run from Sheet1 and paste is to sheet2
Dim R As Range, lR As Long
Set R = Range("A28:J37")
lR = Range("A28:J37").Columns(1).Find("*", LookIn:=xlValues, searchdirection:=xlPrevious).Row
Range("A28:J" & lR).Copy
With Sheets("Sheet2")
    .Range("A1").PasteSpecial Paste:=xlPasteValues
End With
Application.CutCopyMode = False
End Sub


Thanks JoeMo for your awesome code.
I want to keep the destination data be selected after pasting. Now, the whole 10 rows is being selected regardless of empty rows. But, I want to select only those rows which has values.
Means, if we pasted A28:J33 then after pasting, I want only those six rows be selected. But, current code selects 10 rows.
 
Upvote 0
Thanks JoeMo for your awesome code.
I want to keep the destination data be selected after pasting. Now, the whole 10 rows is being selected regardless of empty rows. But, I want to select only those rows which has values.
Means, if we pasted A28:J33 then after pasting, I want only those six rows be selected. But, current code selects 10 rows.
The code I posted will select only the pasted range. So, if 6 rows were pasted, only those 6 rows would be selected on the destination sheet.
 
Upvote 0

Forum statistics

Threads
1,224,740
Messages
6,180,678
Members
452,993
Latest member
FDARYABEE

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