Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default macro for copying a range to a column of cells

I need help with an excel macro that will copy the contents of a range
to a single column of rows.

Scenario:
user selects continuous range R
user executes the macro
user is prompted to select a cell C
If C is included in R user is prompted to select a non-inclusive cell
Data from R is copied, left-to-right, top-to-bottom to destination
cells starting at C

Example. Assuming one char/cell

a b
c d

is copied as

a <- selected cell C
b
c
d

could you please help? TIA

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default macro for copying a range to a column of cells

Maybe this will work for you:

Option Explicit
Sub testme02()

Dim fRng As Range
Dim tRng As Range
Dim myRow As Range
Dim myCell As Range
Dim Resp As Long

Set fRng = Nothing
On Error Resume Next
Set fRng = Application.InputBox(Prompt:="Select a single area range", _
Type:=8).Areas(1)
On Error GoTo 0

If fRng Is Nothing Then
Exit Sub 'user hit cancel
End If

Set tRng = Nothing
On Error Resume Next
Set tRng = Application.InputBox(Prompt:="Select a single cell", _
Type:=8).Cells(1)
On Error GoTo 0

If tRng Is Nothing Then
Exit Sub
End If

'check if same workbook
If fRng.Parent.Parent.Name = tRng.Parent.Parent.Name Then
'check if same worksheet
If fRng.Parent.Name = tRng.Parent.Name Then
'check for overlapping
If Intersect(fRng, tRng.Resize(fRng.Cells.Count)) Is Nothing Then
'no overlap
Else
MsgBox "Please select non-overlapping ranges!"
Exit Sub
End If
End If
End If


If Application.CountA(tRng.Resize(fRng.Cells.Count)) 0 Then
Resp = MsgBox(Prompt:="Wanna overwrite existing data?", _
Buttons:=vbYesNo)
If Resp = vbNo Then
Exit Sub
End If
End If

For Each myRow In fRng.Rows
For Each myCell In myRow.Cells
tRng.Value = myCell.Value
Set tRng = tRng.Offset(1, 0)
Next myCell
Next myRow

End Sub


wrote:

I need help with an excel macro that will copy the contents of a range
to a single column of rows.

Scenario:
user selects continuous range R
user executes the macro
user is prompted to select a cell C
If C is included in R user is prompted to select a non-inclusive cell
Data from R is copied, left-to-right, top-to-bottom to destination
cells starting at C

Example. Assuming one char/cell

a b
c d

is copied as

a <- selected cell C
b
c
d

could you please help? TIA


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default macro for copying a range to a column of cells

Dave Peterson wrote:
Maybe this will work for you:

Sub testme02()

[snip]

Yes it does work perfect. Thank you very much for your time and reply.

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
Copying a column of single cells into a column of merged cells [email protected] Excel Discussion (Misc queries) 1 August 16th 06 01:18 PM
Problems with a finding macro and copying a range of cells Agasnine Excel Programming 1 November 20th 05 07:19 PM
How do I skip blank cells when copying over a range of cells? tawells Excel Discussion (Misc queries) 2 June 7th 05 09:36 PM
copying range column widths rexsalius Excel Programming 2 January 14th 04 07:07 PM
Copying a range of cells MDC[_2_] Excel Programming 2 October 15th 03 03:33 AM


All times are GMT +1. The time now is 12:40 PM.

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"