PC Review


Reply
Thread Tools Rate Thread

Creating a Variable Range

 
 
Uninvisible
Guest
Posts: n/a
 
      24th Oct 2007
I am using the following code to copy a range of cells in Column A and
to paste (special transpose) the range in another area of the
spreadsheet. Only problem is that I have fixed the range here to be
the first 10 cells but it is a variable range which should end when it
has included the last cell to contain an e-mail address following a
cell which has a fixed value (and each range will have this fixed
value):

A1 Erica Smith
A2 Vice President
A3 Company, Inc.
A4 710 Bridgeport Avenue
A5 Southfield, MI 48076
A6 (555)555-5555
A7 (555)555-5555
A8 E-Mail Address Associated Contact Created By Date
A9 n...@internet.com EGOKCE 03/08/06
A10 Darby Smith
A11 Vice President
A12 Company, Inc.
A13 710 Bridgeport Avenue
A14 Southfield, MI 48076
A15 (555)555-5555
A16 E-Mail Address Associated Contact Created By Date
A17 n...@internet.com CATALOGS 03/08/06
A18 na...@internet.com HINGERMA 03/22/06
A19 Carol Smith
A20 Vice President
A21 Company, Inc.
A22 710 Bridgeport Avenue
A23 Southfield, MI 48076
A24 (555)555-5555
A25 E-Mail Address Associated Contact Created By Date
A26 Mike Smith
A27 Vice President

So, the code should auto-identify A1:A9, A10:A18 and A19:A25 as ranges
which will be copied and transposed. It should do this for all 30000
ecords in Column A. Here is what I have so far, any thoughts:

Sub Transpose1()

Dim cnt As Integer
Do
Set rng = Selection.Offset.Resize(10)
Application.CutCopyMode = False
rng.Copy
Range("G" & rng.Row).Select
Do While ActiveCell.Value <> ""
ActiveCell.Offset(1, 0).Select
Loop
Selection.PasteSpecial Transpose:=True
rng.Delete Shift:=xlUp
Range("A" & ActiveCell.Row).Select
cnt = 1
Do
ActiveCell.Offset(-1, 0).Select
cnt = cnt + 1
Loop Until ActiveCell.Value & "" = ""
If cnt < 3 Then
Exit Do
Else
ActiveCell.Offset(1, 0).Select
End If
Loop
End Sub

 
Reply With Quote
 
 
 
 
JE McGimpsey
Guest
Posts: n/a
 
      24th Oct 2007
One way:

Public Sub Transpose1()
Const csSearch As String = "E-Mail Address"
Dim rStart As Range
Dim rDest As Range
Dim nCount As Long
Dim bFound As Boolean

Set rStart = Range("A1")
Set rDest = Range("G1")
Do While rStart.Text <> vbNullString
bFound = False
nCount = 1
Do
With rStart
If bFound Then
If InStr(.Offset(nCount, 0).Text, "@") = 0 Then
.Resize(nCount).Copy
rDest.PasteSpecial Transpose:=True
Set rDest = rDest.Offset(1, 0)
Set rStart = .Offset(nCount)
Exit Do
End If
Else
bFound = InStr(1, .Offset(nCount, 0).Text, csSearch)
End If
End With
nCount = nCount + 1
Loop
Loop
End Sub

In article <(E-Mail Removed)>,
Uninvisible <(E-Mail Removed)> wrote:

> I am using the following code to copy a range of cells in Column A and
> to paste (special transpose) the range in another area of the
> spreadsheet. Only problem is that I have fixed the range here to be
> the first 10 cells but it is a variable range which should end when it
> has included the last cell to contain an e-mail address following a
> cell which has a fixed value (and each range will have this fixed
> value):
>
> A1 Erica Smith
> A2 Vice President
> A3 Company, Inc.
> A4 710 Bridgeport Avenue
> A5 Southfield, MI 48076
> A6 (555)555-5555
> A7 (555)555-5555
> A8 E-Mail Address Associated Contact Created By Date
> A9 n...@internet.com EGOKCE 03/08/06
> A10 Darby Smith
> A11 Vice President
> A12 Company, Inc.
> A13 710 Bridgeport Avenue
> A14 Southfield, MI 48076
> A15 (555)555-5555
> A16 E-Mail Address Associated Contact Created By Date
> A17 n...@internet.com CATALOGS 03/08/06
> A18 na...@internet.com HINGERMA 03/22/06
> A19 Carol Smith
> A20 Vice President
> A21 Company, Inc.
> A22 710 Bridgeport Avenue
> A23 Southfield, MI 48076
> A24 (555)555-5555
> A25 E-Mail Address Associated Contact Created By Date
> A26 Mike Smith
> A27 Vice President
>
> So, the code should auto-identify A1:A9, A10:A18 and A19:A25 as ranges
> which will be copied and transposed. It should do this for all 30000
> ecords in Column A. Here is what I have so far, any thoughts:
>
> Sub Transpose1()
>
> Dim cnt As Integer
> Do
> Set rng = Selection.Offset.Resize(10)
> Application.CutCopyMode = False
> rng.Copy
> Range("G" & rng.Row).Select
> Do While ActiveCell.Value <> ""
> ActiveCell.Offset(1, 0).Select
> Loop
> Selection.PasteSpecial Transpose:=True
> rng.Delete Shift:=xlUp
> Range("A" & ActiveCell.Row).Select
> cnt = 1
> Do
> ActiveCell.Offset(-1, 0).Select
> cnt = cnt + 1
> Loop Until ActiveCell.Value & "" = ""
> If cnt < 3 Then
> Exit Do
> Else
> ActiveCell.Offset(1, 0).Select
> End If
> Loop
> End Sub

 
Reply With Quote
 
Uninvisible
Guest
Posts: n/a
 
      25th Oct 2007
Perfect. Thank you.

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Creating a variable range in Visual Basic Deby Microsoft Excel Programming 2 11th Dec 2009 03:58 PM
Creating a variable of type Range Bob Microsoft Excel Programming 5 13th Oct 2008 10:29 AM
I need your help Dear Vba Guru's..."Creating range in a variable data.." jerome.tamayo@gmail.com Microsoft Excel Programming 2 23rd Jan 2007 08:01 AM
Urgent: Creating an Environment Variable (System Variable)? =?Utf-8?B?U2F1cmFiaA==?= Microsoft Dot NET Framework 1 7th Feb 2005 05:51 PM
setting a range variable equal to the value of a string variable Pilgrim Microsoft Excel Programming 2 1st Jul 2004 11:32 PM


Features
 

Advertising
 

Newsgroups
 


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