Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 852
Default Transpose a column list to every other cell in a row on anothersheet, then center


I want to transpose a column list of names to every other cell in a row on another sheet and then "center across selection" each name with the cell it is in plus the cell to the right.

The list on sheet 1 will vary from 4 to 10, 20 names.

So on sheet 3 cells D4 and E4 would have a name centered on them, cells F4 and G4 would have the next name centered on them and so on for all the names in the row.

The previous transposed & centered names need to be cleared and the new transposed set of names overwritten to cell D4 each time the code is run.

This code puts the names in the correct spot on sheet 3, but all in a continuous row.

Thanks,
Howard

Sub Name_Hours_OPNumber()

Dim nhoRng As Range

Set nhoRng = Sheets("Sheet1").Range("D7:D" & Cells(Rows.Count, "D").End(xlUp).Row)
nhoRng.Copy
Sheets("Sheet3").Range("D4").PasteSpecial Paste:=xlPasteAll, Transpose:=True

End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,872
Default Transpose a column list to every other cell in a row on another sheet, then center

Hi Howard,

Am Thu, 13 Aug 2015 22:49:29 -0700 (PDT) schrieb L. Howard:

I want to transpose a column list of names to every other cell in a row on another sheet and then "center across selection" each name with the cell it is in plus the cell to the right.

The list on sheet 1 will vary from 4 to 10, 20 names.


try:

Sub Name_Hours_OPNumber()

Dim vardata As Variant
Dim i As Long, n As Long

Application.ScreenUpdating = False

With Sheets("Sheet1")
vardata = .Range("D7:D" & .Cells(Rows.Count, "D").End(xlUp).Row)
End With
n = 4

For i = LBound(vardata) To UBound(vardata)
With Sheets("Sheet3")
.Activate
.Cells(4, n) = vardata(i, 1)
.Range(Cells(4, n), Cells(4, n + 1)).Select
Selection.HorizontalAlignment = xlCenterAcrossSelection
End With
n = n + 2
Next
Application.ScreenUpdating = True
End Sub


Regards
Claus B.
--
Vista Ultimate / Windows7
Office 2007 Ultimate / 2010 Professional
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 852
Default Transpose a column list to every other cell in a row on anothersheet, then center



try:

Sub Name_Hours_OPNumber()

Dim vardata As Variant
Dim i As Long, n As Long

Application.ScreenUpdating = False

With Sheets("Sheet1")
vardata = .Range("D7:D" & .Cells(Rows.Count, "D").End(xlUp).Row)
End With
n = 4

For i = LBound(vardata) To UBound(vardata)
With Sheets("Sheet3")
.Activate
.Cells(4, n) = vardata(i, 1)
.Range(Cells(4, n), Cells(4, n + 1)).Select
Selection.HorizontalAlignment = xlCenterAcrossSelection
End With
n = n + 2
Next
Application.ScreenUpdating = True
End Sub


Regards
Claus B.
--


Hi Claus,

Very nice! Works excellent. Thank you.

I added some lines to do additional stuff.

Do you see any glaring errors? It does exactly what I want it to do, but may not be best coding practices.

Howard

Sub Name_Hours_OPNumber()

Dim vardata As Variant
Dim i As Long, n As Long

Application.ScreenUpdating = False

With Sheets("Sheet3").Range("4:5")
.ClearContents
.HorizontalAlignment = xlGeneral
.VerticalAlignment = xlBottom
.WrapText = True
End With

With Sheets("Sheet1")
vardata = .Range("D7:D" & .Cells(Rows.Count, "D").End(xlUp).Row)
End With

n = 4

For i = LBound(vardata) To UBound(vardata)

With Sheets("Sheet3")
.Activate
.Cells(4, n) = vardata(i, 1)
.Cells(5, n) = "Hours"
.Cells(5, n + 1) = "OP Number"
.Range(Cells(4, n), Cells(4, n + 1)).Select
Selection.HorizontalAlignment = xlCenterAcrossSelection
End With

n = n + 2
Next

[D6].Activate
Application.ScreenUpdating = True

End Sub
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,872
Default Transpose a column list to every other cell in a row on another sheet, then center

Hi Howard,

Am Fri, 14 Aug 2015 03:34:58 -0700 (PDT) schrieb L. Howard:

I added some lines to do additional stuff.

Do you see any glaring errors? It does exactly what I want it to do, but may not be best coding practices.


no, every thing is okay.

But delete [D6].Activate at the end of the code
It's not good practice and also superfluous.

If you want go back to D6 then try it with
Application.Goto range("D6")


Regards
Claus B.
--
Vista Ultimate / Windows7
Office 2007 Ultimate / 2010 Professional
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 852
Default Transpose a column list to every other cell in a row on anothersheet, then center

On Friday, August 14, 2015 at 3:58:18 AM UTC-7, Claus Busch wrote:
Hi Howard,

Am Fri, 14 Aug 2015 03:34:58 -0700 (PDT) schrieb L. Howard:

I added some lines to do additional stuff.

Do you see any glaring errors? It does exactly what I want it to do, but may not be best coding practices.


no, every thing is okay.

But delete [D6].Activate at the end of the code
It's not good practice and also superfluous.

If you want go back to D6 then try it with
Application.Goto range("D6")


Regards
Claus B.



Okay, and thanks again.

Howard
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
transpose rows to column (cell) Ghaleb Bakri Excel Discussion (Misc queries) 3 January 4th 10 09:04 AM
How to transpose and concatenate long list in one column? CSchwass Excel Worksheet Functions 12 September 11th 09 12:46 AM
Move to specific sheet and cell based on criteria entered on anothersheet [email protected] Excel Programming 1 July 15th 08 03:52 PM
check text in cell for at least one keyword from a list on anothersheet Brotherharry Excel Worksheet Functions 4 December 10th 07 03:23 PM
find first empty cell in column and start transpose next row in that cell ali Excel Discussion (Misc queries) 6 July 21st 07 11:55 PM


All times are GMT +1. The time now is 02:04 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"