Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 25
Default VBA - specify where data is placed on new sheet

I am attempting to modify a VBA posted on this site.

This works great for making one continuos column from a lot of other columns
but what I'm trying to do is paste Columns N,S & X underneath each other in
Column A of the new sheet, then paste Columns O,T & Y underneath each other
in Column B of the new sheet, etc. etc.

The columns will be of various lengths each month.

Any help would be most appreciated.

Cathy


Sub OneColumnV2()
''''''''''''''''''''''''''''''''''''''''''
'Macro to copy columns of variable length'
'into 1 continous column in a new sheet '
'Modified 17 FEb 2006 by Bernie Dietrick
''''''''''''''''''''''''''''''''''''''''''
Dim iLastcol As Long
Dim iLastRow As Long
Dim jLastrow As Long
Dim ColNdx As Long
Dim ws As Worksheet
Dim myRng As Range
Dim ExcludeBlanks As Boolean
Dim mycell As Range

ExcludeBlanks = (MsgBox("Exclude Blanks", vbYesNo) = vbYes)
Set ws = ActiveSheet
iLastcol = ws.Cells(1, ws.Columns.Count).End(xlToLeft).Column
On Error Resume Next

Application.DisplayAlerts = False
Worksheets("Alldata").Delete
Application.DisplayAlerts = True

Sheets.Add.Name = "Alldata"

For ColNdx = 1 To iLastcol

iLastRow = ws.Cells(ws.Rows.Count, ColNdx).End(xlUp).Row

Set myRng = ws.Range(ws.Cells(1, ColNdx), _
ws.Cells(iLastRow, ColNdx))

If ExcludeBlanks Then
For Each mycell In myRng
If mycell.Value < "" Then
jLastrow = Sheets("Alldata").Cells(Rows.Count, 1) _
.End(xlUp).Row
mycell.Copy
Sheets("Alldata").Cells(jLastrow + 1, 1) _
.PasteSpecial xlPasteValues
End If
Next mycell
Else
myRng.Copy
jLastrow = Sheets("Alldata").Cells(Rows.Count, 1) _
.End(xlUp).Row
mycell.Copy
Sheets("Alldata").Cells(jLastrow + 1, 1) _
.PasteSpecial xlPasteValues
End If
Next

Sheets("Alldata").Rows("1:1").EntireRow.Delete

ws.Activate
End Sub



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,290
Default VBA - specify where data is placed on new sheet

Cathy,

The logic...
find the bottom of Column N
find the bottom of Column A (new sheet)
paste column N at bottom of Column A (new sheet)

find the bottom of Column S
find the bottom of Column A (new sheet)
paste Column S at bottom of Column A (new sheet)

same for Column X

To find the first empty cell at the bottom of a column use...
With Worksheets("OldSheet")
Set rngCell = .Cells(.Rows.Count, "N").End (xlUp)(2, 1)
End With
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware




"CathyH"
wrote in message
I am attempting to modify a VBA posted on this site.

This works great for making one continuos column from a lot of other columns
but what I'm trying to do is paste Columns N,S & X underneath each other in
Column A of the new sheet, then paste Columns O,T & Y underneath each other
in Column B of the new sheet, etc. etc.

The columns will be of various lengths each month.

Any help would be most appreciated.

Cathy


Sub OneColumnV2()
''''''''''''''''''''''''''''''''''''''''''
'Macro to copy columns of variable length'
'into 1 continous column in a new sheet '
'Modified 17 FEb 2006 by Bernie Dietrick
''''''''''''''''''''''''''''''''''''''''''
Dim iLastcol As Long
Dim iLastRow As Long
Dim jLastrow As Long
Dim ColNdx As Long
Dim ws As Worksheet
Dim myRng As Range
Dim ExcludeBlanks As Boolean
Dim mycell As Range

ExcludeBlanks = (MsgBox("Exclude Blanks", vbYesNo) = vbYes)
Set ws = ActiveSheet
iLastcol = ws.Cells(1, ws.Columns.Count).End(xlToLeft).Column
On Error Resume Next

Application.DisplayAlerts = False
Worksheets("Alldata").Delete
Application.DisplayAlerts = True

Sheets.Add.Name = "Alldata"

For ColNdx = 1 To iLastcol

iLastRow = ws.Cells(ws.Rows.Count, ColNdx).End(xlUp).Row

Set myRng = ws.Range(ws.Cells(1, ColNdx), _
ws.Cells(iLastRow, ColNdx))

If ExcludeBlanks Then
For Each mycell In myRng
If mycell.Value < "" Then
jLastrow = Sheets("Alldata").Cells(Rows.Count, 1) _
.End(xlUp).Row
mycell.Copy
Sheets("Alldata").Cells(jLastrow + 1, 1) _
.PasteSpecial xlPasteValues
End If
Next mycell
Else
myRng.Copy
jLastrow = Sheets("Alldata").Cells(Rows.Count, 1) _
.End(xlUp).Row
mycell.Copy
Sheets("Alldata").Cells(jLastrow + 1, 1) _
.PasteSpecial xlPasteValues
End If
Next

Sheets("Alldata").Rows("1:1").EntireRow.Delete

ws.Activate
End Sub



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 25
Default VBA - specify where data is placed on new sheet

I'm having no luck with this but I'm a VBA newbie/dunce plus my mouse stopped
working so I'm quitting.

"Jim Cone" wrote:

Cathy,

The logic...
find the bottom of Column N
find the bottom of Column A (new sheet)
paste column N at bottom of Column A (new sheet)

find the bottom of Column S
find the bottom of Column A (new sheet)
paste Column S at bottom of Column A (new sheet)

same for Column X

To find the first empty cell at the bottom of a column use...
With Worksheets("OldSheet")
Set rngCell = .Cells(.Rows.Count, "N").End (xlUp)(2, 1)
End With
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware




"CathyH"
wrote in message
I am attempting to modify a VBA posted on this site.

This works great for making one continuos column from a lot of other columns
but what I'm trying to do is paste Columns N,S & X underneath each other in
Column A of the new sheet, then paste Columns O,T & Y underneath each other
in Column B of the new sheet, etc. etc.

The columns will be of various lengths each month.

Any help would be most appreciated.

Cathy


Sub OneColumnV2()
''''''''''''''''''''''''''''''''''''''''''
'Macro to copy columns of variable length'
'into 1 continous column in a new sheet '
'Modified 17 FEb 2006 by Bernie Dietrick
''''''''''''''''''''''''''''''''''''''''''
Dim iLastcol As Long
Dim iLastRow As Long
Dim jLastrow As Long
Dim ColNdx As Long
Dim ws As Worksheet
Dim myRng As Range
Dim ExcludeBlanks As Boolean
Dim mycell As Range

ExcludeBlanks = (MsgBox("Exclude Blanks", vbYesNo) = vbYes)
Set ws = ActiveSheet
iLastcol = ws.Cells(1, ws.Columns.Count).End(xlToLeft).Column
On Error Resume Next

Application.DisplayAlerts = False
Worksheets("Alldata").Delete
Application.DisplayAlerts = True

Sheets.Add.Name = "Alldata"

For ColNdx = 1 To iLastcol

iLastRow = ws.Cells(ws.Rows.Count, ColNdx).End(xlUp).Row

Set myRng = ws.Range(ws.Cells(1, ColNdx), _
ws.Cells(iLastRow, ColNdx))

If ExcludeBlanks Then
For Each mycell In myRng
If mycell.Value < "" Then
jLastrow = Sheets("Alldata").Cells(Rows.Count, 1) _
.End(xlUp).Row
mycell.Copy
Sheets("Alldata").Cells(jLastrow + 1, 1) _
.PasteSpecial xlPasteValues
End If
Next mycell
Else
myRng.Copy
jLastrow = Sheets("Alldata").Cells(Rows.Count, 1) _
.End(xlUp).Row
mycell.Copy
Sheets("Alldata").Cells(jLastrow + 1, 1) _
.PasteSpecial xlPasteValues
End If
Next

Sheets("Alldata").Rows("1:1").EntireRow.Delete

ws.Activate
End Sub




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,290
Default VBA - specify where data is placed on new sheet


Sub MakeLongColumns()
Dim lngCounter As Long
Dim lngBottom As Long
Dim lngTemp As Long
Dim lngCol As Long
Dim N As Long
lngCounter = 0
lngTemp = 1
lngCol = 1

For N = 14 To 64 Step 5
With Worksheets("OldSheet")
lngBottom = .Cells(.Rows.Count, N).End(xlUp).Row
.Range(.Cells(1, N), .Cells(lngBottom, N)).Copy _
Destination:=Worksheets("NewSheet").Cells(lngTemp, lngCol)
End With
lngCounter = lngCounter + 1
lngTemp = lngTemp + lngBottom
If lngCounter Mod 3 = 0 Then
lngCol = lngCol + 1
lngTemp = 1
End If
Next
End Sub
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware
(Excel add-ins... sort colors, compare, arrange columns, thesaurus)



"CathyH"
wrote in message
I'm having no luck with this but I'm a VBA newbie/dunce plus my mouse stopped
working so I'm quitting.

"Jim Cone" wrote:

Cathy,

The logic...
find the bottom of Column N
find the bottom of Column A (new sheet)
paste column N at bottom of Column A (new sheet)

find the bottom of Column S
find the bottom of Column A (new sheet)
paste Column S at bottom of Column A (new sheet)

same for Column X

To find the first empty cell at the bottom of a column use...
With Worksheets("OldSheet")
Set rngCell = .Cells(.Rows.Count, "N").End (xlUp)(2, 1)
End With
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware




"CathyH"
wrote in message
I am attempting to modify a VBA posted on this site.

This works great for making one continuos column from a lot of other columns
but what I'm trying to do is paste Columns N,S & X underneath each other in
Column A of the new sheet, then paste Columns O,T & Y underneath each other
in Column B of the new sheet, etc. etc.

The columns will be of various lengths each month.

Any help would be most appreciated.

Cathy


Sub OneColumnV2()
''''''''''''''''''''''''''''''''''''''''''
'Macro to copy columns of variable length'
'into 1 continous column in a new sheet '
'Modified 17 FEb 2006 by Bernie Dietrick
''''''''''''''''''''''''''''''''''''''''''
Dim iLastcol As Long
Dim iLastRow As Long
Dim jLastrow As Long
Dim ColNdx As Long
Dim ws As Worksheet
Dim myRng As Range
Dim ExcludeBlanks As Boolean
Dim mycell As Range

ExcludeBlanks = (MsgBox("Exclude Blanks", vbYesNo) = vbYes)
Set ws = ActiveSheet
iLastcol = ws.Cells(1, ws.Columns.Count).End(xlToLeft).Column
On Error Resume Next

Application.DisplayAlerts = False
Worksheets("Alldata").Delete
Application.DisplayAlerts = True

Sheets.Add.Name = "Alldata"

For ColNdx = 1 To iLastcol

iLastRow = ws.Cells(ws.Rows.Count, ColNdx).End(xlUp).Row

Set myRng = ws.Range(ws.Cells(1, ColNdx), _
ws.Cells(iLastRow, ColNdx))

If ExcludeBlanks Then
For Each mycell In myRng
If mycell.Value < "" Then
jLastrow = Sheets("Alldata").Cells(Rows.Count, 1) _
.End(xlUp).Row
mycell.Copy
Sheets("Alldata").Cells(jLastrow + 1, 1) _
.PasteSpecial xlPasteValues
End If
Next mycell
Else
myRng.Copy
jLastrow = Sheets("Alldata").Cells(Rows.Count, 1) _
.End(xlUp).Row
mycell.Copy
Sheets("Alldata").Cells(jLastrow + 1, 1) _
.PasteSpecial xlPasteValues
End If
Next

Sheets("Alldata").Rows("1:1").EntireRow.Delete

ws.Activate
End Sub




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 25
Default VBA - specify where data is placed on new sheet

How do I then say: for Column O, start at Row 1, Column "B" (new sheet)?

"Jim Cone" wrote:

Cathy,

The logic...
find the bottom of Column N
find the bottom of Column A (new sheet)
paste column N at bottom of Column A (new sheet)

find the bottom of Column S
find the bottom of Column A (new sheet)
paste Column S at bottom of Column A (new sheet)

same for Column X

To find the first empty cell at the bottom of a column use...
With Worksheets("OldSheet")
Set rngCell = .Cells(.Rows.Count, "N").End (xlUp)(2, 1)
End With
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware




"CathyH"
wrote in message
I am attempting to modify a VBA posted on this site.

This works great for making one continuos column from a lot of other columns
but what I'm trying to do is paste Columns N,S & X underneath each other in
Column A of the new sheet, then paste Columns O,T & Y underneath each other
in Column B of the new sheet, etc. etc.

The columns will be of various lengths each month.

Any help would be most appreciated.

Cathy





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,290
Default VBA - specify where data is placed on new sheet


Sub MakeLongColumns_R1()
'Jim Cone - San Francisco - USA - 06/06/2007
Dim lngCounter As Long
Dim lngBottom As Long
Dim lngTemp As Long
Dim lngCol As Long
Dim M As Long
Dim N As Long
lngCounter = 0
lngTemp = 1
lngCol = 1

For M = 1 To 15
For N = (M + 13) To (M + 23) Step 5
With Worksheets("OldSheet")
lngBottom = .Cells(.Rows.Count, N).End(xlUp).Row
.Range(.Cells(1, N), .Cells(lngBottom, N)).Copy _
Destination:=Worksheets("NewSheet").Cells(lngTemp, lngCol)
End With
lngCounter = lngCounter + 1
lngTemp = lngTemp + lngBottom
If lngCounter Mod 3 = 0 Then
lngCol = lngCol + 1
lngTemp = 1
End If
Next
Next
End Sub
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware



"CathyH"
wrote in message
How do I then say: for Column O, start at Row 1, Column "B" (new sheet)?

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
Need help Taking alot data from one sheet (if not blank) and copying toa list on another sheet. Alex Zuniga Excel Worksheet Functions 1 November 25th 09 11:54 PM
Duplicate sheet, autonumber sheet, record data on another sheet des-sa[_2_] Excel Worksheet Functions 0 May 8th 08 06:56 PM
Hyperlinking from data in one sheet to matching data in another sheet Phrank Excel Worksheet Functions 6 December 18th 07 09:58 AM
Data copy from a seperate sheet to data sheet ZeroXevo Excel Programming 1 June 20th 05 08:14 AM
pull data from sheet two, then fill in the data to sheet one (part Jim Excel Worksheet Functions 3 December 11th 04 04:51 AM


All times are GMT +1. The time now is 10:17 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"