Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / New Users / April 2008

Tip: Looking for answers? Try searching our database.

Changing data orientation from one sheet to another

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Olga - 20 Apr 2008 18:55 GMT
Hi,
On sheet1 the data is oriented vertically as
A1
A2
A3
I'd like on sheet2 the data be oriented horizontally
A1 to A1
A2 to B1
A3 to B3
Can it be done? if so, how?
TIA
Olga
Excell 07
Gord Dibben - 20 Apr 2008 19:32 GMT
Copy the data from sheet1

Select A1 of sheet2 and paste special>transpose.

Note:  cannot be done if you have more than 16384 rows of data in column A

Also, I think you have a typo at  A3 to B3.........maybe A3 to C1?

Gord Dibben  MS Excel MVP

>Hi,
>On sheet1 the data is oriented vertically as
[quoted text clipped - 9 lines]
>Olga
>Excell 07
Olga - 20 Apr 2008 20:05 GMT
Thank you Gord,
The data is coming from a SQL query and it is text and money values. If I
copy A1 from sheet 1 and paste it as transpose on sheet2 works however, if I
drag A1 horizontally to fulfill the rest of the cells then, the information
is not coherent. Surly I'm doing some wrong.

> Copy the data from sheet1
>
[quoted text clipped - 19 lines]
>>Olga
>>Excell 07
Gord Dibben - 20 Apr 2008 21:54 GMT
"Surley I'm doing some wrong"

Yes, you are<g>

Re-read the instructions................I did not say to copy A1 from sheet1

Select the data range on sheet1 and copy.

Select A1 on sheet2 and Edit>Paste Special>Transpose>OK>Esc

No dragging needed.  You are paste/transposing the copied range, not just one
cell.

Gord

>Thank you Gord,
>The data is coming from a SQL query and it is text and money values. If I
[quoted text clipped - 25 lines]
>>>Olga
>>>Excell 07
Olga - 20 Apr 2008 22:54 GMT
Thank you very much, it worked. But how would sheet 2 update itself when
sheet 1 is updated refreshing the db connection?

> "Surley I'm doing some wrong"
>
[quoted text clipped - 45 lines]
>>>>Olga
>>>>Excell 07
Gord Dibben - 20 Apr 2008 23:58 GMT
Sheet2 will not update itself using the manual transpose method we just did.

We will have to link the cells to the source range then tranpose those links.

Or write a macro to do the job after each query.

What is your original source range that will be transposed?

Is it consistent or variable range?

Gord

>Thank you very much, it worked. But how would sheet 2 update itself when
>sheet 1 is updated refreshing the db connection?
[quoted text clipped - 48 lines]
>>>>>Olga
>>>>>Excell 07
Olga - 21 Apr 2008 07:15 GMT
The original sourse range is composed of two columns containing labels(A1)
and numbers (euros B1).
It's variable, every month a new row is added by the query.

> Sheet2 will not update itself using the manual transpose method we just
> did.
[quoted text clipped - 66 lines]
>>>>>>Olga
>>>>>>Excell 07
Gord Dibben - 22 Apr 2008 18:08 GMT
If once a month, automation should not really be required.

But, this macro can be run to copy the sheet1 data to a new sheet.

Sub select_transpose()
   Range(Range("A1:B1"), Cells(Rows.Count, Selection.Column).End(xlUp)).Copy
   Sheets.Add
   Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
       False, Transpose:=True
   Application.CutCopyMode = False
   Range("A1").Select
End Sub

Gord

>The original sourse range is composed of two columns containing labels(A1)
>and numbers (euros B1).
[quoted text clipped - 70 lines]
>>>>>>>Olga
>>>>>>>Excell 07
Olga - 22 Apr 2008 20:19 GMT
Hi Gord,
apparently I need to do my transformation manually or by recording  a macro
because otherwise, my cells options (borders, alignments, colors, etc) get
mist up when actualizing the data/ query. Using the below test micro, only
the data is updated leaving the cells format intact. My problems is that I've
over 100 cells (a + b = 200) to manually transform. So, perhaps, I need to
think of a loop.
------------------------------------------------------
Sub Macro2()
Sheets("TEST").Select
   Range("B16").Select
   Application.CutCopyMode = False
   ActiveCell.FormulaR1C1 = "=DB!R[-14]C[-1]"
   Range("C16").Select
   ActiveCell.FormulaR1C1 = "=DB!R[-13]C[-2]"
   Range("D16").Select
   ActiveCell.FormulaR1C1 = "=DB!R[-12]C[-3]"
   Range("E16").Select
   ActiveCell.FormulaR1C1 = "=DB!R[-11]C[-4]"
   Range("B17").Select
   ActiveCell.FormulaR1C1 = "=DB!R[-15]C"
   Range("C17").Select
   ActiveCell.FormulaR1C1 = "=DB!R[-14]C[-1]"
   Range("D17").Select
   ActiveCell.FormulaR1C1 = "=DB!R[-13]C[-2]"
   Range("E17").Select
   ActiveCell.FormulaR1C1 = "=DB!R[-12]C[-3]"
   Range("E18").Select
End Sub

--------------------------------------------------------------

> If once a month, automation should not really be required.
>
[quoted text clipped - 89 lines]
>>>>>>>>Olga
>>>>>>>>Excell 07
Gord Dibben - 23 Apr 2008 00:23 GMT
Did you try the macro I supplied?

What alterations do you think it needs?

Why do you think you need to link the cells if the changes are to be made once a
month?

Gord

>Hi Gord,
>apparently I need to do my transformation manually or by recording  a macro
[quoted text clipped - 121 lines]
>>>>>>>>>Olga
>>>>>>>>>Excell 07
Olga - 23 Apr 2008 08:14 GMT
Hello Gord, thank you for your support.

Yes I did test your macro; in fact, thanks to you, I learned how to use
them. I made a little change to your working macro so that it always points
to the same datasheet (DB) and paste the copy in the same worksheet (TEST).

---------------------------------------

Sub select_transpose()
  Sheets("DB").Select
  Range(Range("A2:B70"), Cells(Rows.Count,
Selection.Column).End(xlUp)).Copy
   'Sheets.Add
   Sheets("TEST").Select
   Range("A2").Select
   Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone,
SkipBlanks:= _
       False, Transpose:=True
   Application.CutCopyMode = False
  'Range("A2").Select
End Sub

------------------------------------

Ones pasted the information; I need to format the cells giving color, type
of text, size. in few words, making it looking nice. Now, if I run the macro
again, I lose all the cells formats, thus my work. Even if I need to do it
once a month, why repeat all the work done? That's why I thought of my
recorded macro which does leave the cells format intact updating only the
containing data. I tried to format the datasheet so that the format can be
pasted as well but it's not the same as formatting the worksheet itself, in
my case. I hope to have explained myself well, English is not my native
language and sorry for the time delay, I'm in Spain.

Olga

> Did you try the macro I supplied?
>
[quoted text clipped - 137 lines]
>>>>>>>>>>Olga
>>>>>>>>>>Excell 07
Gord Dibben - 24 Apr 2008 00:54 GMT
Easiest in my opinion would be to record a macro whilst doing the formatting
once then run that in conjunction with the select_transpose macro?

Once a month run the select_transpose then run the formatting macro?

Alternative method is to link the transposed data to the original columns on DB
sheet.

This macro copies from DB sheet to TEST sheet and links the cells.

Sub select_and_Link()
  Sheets("DB").Select
  Range(Range("A2:B2"), Cells(Rows.Count, _
       Selection.Column).End(xlUp)).Copy
   Sheets("TEST").Select
   With ActiveSheet
   .Range("A4").Select
   .Paste Link:=True
   End With
   Application.CutCopyMode = False
End Sub

Now, one time run this John Walkenbach macro to Transpose the linked formulas
but note that I guess it would have to be run again when your query adds a row
to DB which will kill the formatting again.

Sub Transpose_Formulas()
Dim SRange As Range, dCell As Range
Dim sCell As Range, i As Integer, J As Integer
Dim str As String

   'get input ranges.  default box is filled by use of text
   'variable set to the selected address
   str = Selection.Address(False, False)
   Application.ScreenUpdating = True
   On Error Resume Next
   Set SRange = Application.InputBox(prompt:= _
           "Select the range of cells to be transposed." & Chr(10) & Chr(10) _
           & "If cells do not have Formulas, Sub will end!.", _
           Type:=8, Default:=str)
   If Not SRange.HasFormula Then
       MsgBox "Cells do not contain formulas"
       End
   Else
       If SRange.HasFormula Then
           Set dCell = Application.InputBox(prompt:= _
                   "Select the top left cell of the output location.", _
                   Type:=8)
           If dCell Is Nothing Then End
           On Error GoTo 0
   'set single cell references for use in the next step
           Set sCell = SRange.Cells(1, 1)
           Set dCell = dCell.Cells(1, 1)

   'loop through all cells, working backward to the top left cell
           For i = SRange.Rows.Count - 1 To 0 Step -1
               For J = SRange.Columns.Count - 1 To 0 Step -1
                   If i > 0 Or J > 0 Then
   'do this for all but the first cell
                       sCell.Offset(i, J).Cut _
                               Destination:=dCell.Offset(J, i)

                   Else
   'do top corner last.  Otherwise references are changed
                       sCell.Cut Destination:=dCell
                   End If
               Next J
           Next i
       End If
   End If

End Sub

Gord

>Hello Gord, thank you for your support.
>
[quoted text clipped - 31 lines]
>
>Olga
Gord Dibben - 24 Apr 2008 05:04 GMT
There has to be a better way<g>

I'll keep working on it.

Gord

>Easiest in my opinion would be to record a macro whilst doing the formatting
>once then run that in conjunction with the select_transpose macro?
[quoted text clipped - 106 lines]
>>
>>Olga
Olga - 24 Apr 2008 22:20 GMT
hahaha There's a better way to do it. That is to use PIVOT in my SQL query
but that's an other story..
Thank you.

> There has to be a better way<g>
>
[quoted text clipped - 124 lines]
>>>
>>>Olga

Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.