Copy all values in a row until blank then copy to another sheet

markaxtell

New Member
Joined
Jan 6, 2012
Messages
33
Hi,

I currently have a list of names that will always be a variable number so for example will be column K down to max number of 100 and i want to be able to copy all the names until the blank column and then paste them to another sheet.

Need this to be macro as aware you can do this with specialcells etc

Thanks in advance for help
 
I currently have this

Sub trythis()
Sheets("Sheet1").Range("k1").CurrentRegion.Copy Sheets("Sheet2").Range("c1")
End Sub

But it does not seem to work.

I want to copy all of the data it finds from K1 until row where it is blank then copy it to another sheet starting at C1 down
 
Upvote 0
Hi,

I currently have a list of names that will always be a variable number so for example will be column K down to max number of 100 and i want to be able to copy all the names until the blank column and then paste them to another sheet.

Need this to be macro as aware you can do this with specialcells etc

Thanks in advance for help

The code will copy your names (you choose the cell where your names begin) and paste them to sheet2 starting from whichever cell you want.

Code:
Sub CopyNames()
Dim Lrow As Long
Dim Answer As String, CopyTo As String
Dim CopyRng As Range
Application.ScreenUpdating = False
Answer = InputBox("Please enter your starting cell", "Copy Names")
Lrow = Range(Answer).End(xlDown).Row
MsgBox Lrow
Set CopyRng = Range(Answer & ":" & Range(Answer).End(xlDown).Address)
CopyRng.Copy
Worksheets(2).Activate
CopyTo = InputBox("Please enter the cell to copy", "Copy Names")
Range(CopyTo).Select
ActiveSheet.Paste
Application.CutCopyMode = False
Application.ScreenUpdating = True
End Sub

George
 
Upvote 0
The code will copy your names (you choose the cell where your names begin) and paste them to sheet2 starting from whichever cell you want.

Code:
Sub CopyNames()
Dim Lrow As Long
Dim Answer As String, CopyTo As String
Dim CopyRng As Range
Application.ScreenUpdating = False
Answer = InputBox("Please enter your starting cell", "Copy Names")
Lrow = Range(Answer).End(xlDown).Row
MsgBox Lrow
Set CopyRng = Range(Answer & ":" & Range(Answer).End(xlDown).Address)
CopyRng.Copy
Worksheets(2).Activate
CopyTo = InputBox("Please enter the cell to copy", "Copy Names")
Range(CopyTo).Select
ActiveSheet.Paste
Application.CutCopyMode = False
Application.ScreenUpdating = True
End Sub

George

geroge, thanks for that but how do i get it to do it without the input box?
 
Upvote 0
We can leave it out if the ranges do not change.

If it is always Column K where the names are and always Sheets(2),column C where you want the names to be copied I will amend the code leaving out the input boxes. I just included it in case the ranges were not the same
 
Upvote 0
So what would the code look like and also i would like it if could paste special just the value's and not copy the formatting?
 
Upvote 0
This will do it

Code:
Sub CopyNames()
Dim Lrow As Long
Dim CopyRng As Range
Application.ScreenUpdating = False
Lrow = Range("k2").End(xlDown).Row
'MsgBox Lrow
Set CopyRng = Range("k2" & ":" & "k" & Lrow)
CopyRng.Copy
Worksheets(2).Activate
Range("c1").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Application.ScreenUpdating = True
End Sub
 
Upvote 0
And this if you don't want the formating to be copied

Code:
Sub CopyNames()
Dim Lrow As Long
Dim CopyRng As Range
Application.ScreenUpdating = False
Lrow = Range("k2").End(xlDown).Row
'MsgBox Lrow
Set CopyRng = Range("k2" & ":" & "k" & Lrow)
CopyRng.Copy
Worksheets(2).Range("c1").PasteSpecial Paste:=xlPasteValues
Application.CutCopyMode = False
Application.ScreenUpdating = True
End Sub
 
Upvote 0
that works but i need to run the macro in sheet2 (Summary) where the data will be copied to from Sheet1 (Data).

Sorry for being so specail!
 
Upvote 0
<TABLE style="WIDTH: 240pt; BORDER-COLLAPSE: collapse" border=0 cellSpacing=0 cellPadding=0 width=320><COLGROUP><COL style="WIDTH: 48pt" span=5 width=64><TBODY><TR style="HEIGHT: 12.75pt" height=17><TD style="BORDER-BOTTOM: #d4d0c8; BORDER-LEFT: #d4d0c8; BACKGROUND-COLOR: transparent; WIDTH: 240pt; HEIGHT: 12.75pt; BORDER-TOP: #d4d0c8; BORDER-RIGHT: #d4d0c8; mso-ignore: colspan" height=17 width=320 colSpan=5>Developer Tab ---> Insert Button in the Forms Control Area</TD></TR><TR style="HEIGHT: 12.75pt" height=17><TD style="BORDER-BOTTOM: #d4d0c8; BORDER-LEFT: #d4d0c8; BACKGROUND-COLOR: transparent; HEIGHT: 12.75pt; BORDER-TOP: #d4d0c8; BORDER-RIGHT: #d4d0c8; mso-ignore: colspan" height=17 colSpan=5>Right Click the button ---> Assign Macro --->Choose Copy Names

and use the following code


</TD></TR><TR style="HEIGHT: 12.75pt" height=17><TD style="BORDER-BOTTOM: #d4d0c8; BORDER-LEFT: #d4d0c8; BACKGROUND-COLOR: transparent; HEIGHT: 12.75pt; BORDER-TOP: #d4d0c8; BORDER-RIGHT: #d4d0c8" height=17></TD><TD style="BORDER-BOTTOM: #d4d0c8; BORDER-LEFT: #d4d0c8; BACKGROUND-COLOR: transparent; BORDER-TOP: #d4d0c8; BORDER-RIGHT: #d4d0c8"></TD><TD style="BORDER-BOTTOM: #d4d0c8; BORDER-LEFT: #d4d0c8; BACKGROUND-COLOR: transparent; BORDER-TOP: #d4d0c8; BORDER-RIGHT: #d4d0c8"></TD><TD style="BORDER-BOTTOM: #d4d0c8; BORDER-LEFT: #d4d0c8; BACKGROUND-COLOR: transparent; BORDER-TOP: #d4d0c8; BORDER-RIGHT: #d4d0c8"></TD><TD style="BORDER-BOTTOM: #d4d0c8; BORDER-LEFT: #d4d0c8; BACKGROUND-COLOR: transparent; BORDER-TOP: #d4d0c8; BORDER-RIGHT: #d4d0c8"></TD></TR></TBODY></TABLE>
Code:
Sub CopyNames()
Dim Lrow As Long
Dim CopyRng As Range
Application.ScreenUpdating = False
Worksheets("Data").Activate
Lrow = Range("k2").End(xlDown).Row
'MsgBox Lrow
Set CopyRng = Range("k2" & ":" & "k" & Lrow)
CopyRng.Copy
Worksheets("Summary").Range("c1").PasteSpecial Paste:=xlPasteValues
Worksheets("Summary").Activate
Application.CutCopyMode = False
Application.ScreenUpdating = True
End Sub
 
Upvote 0

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