Macro for Copying group of cells and paste as row [Closed]

Report
Posts
7
Registration date
Wednesday November 8, 2017
Status
Member
Last seen
December 13, 2017
-
 Blocked Profile -
Hi,

I need some help i need a Macro Code to arrange certain cells and prepare it as a row.

I export the file from SharePoint in Excel Format. The data of the form is in Linear.
The data comes in one row. However I need to transpose and get the Set of Cells in Row By Row.

For Example: J1:R9 is one set then S1:AA1 must come below. Its a pattern of 9 Fields.

Please help.

2 replies

OK, Is the file always named the same? If not, then copy it locally, and name it SHAREPOINTINPUT.

Now, open up a new workbook, and click on Data>import from text.

When it asks how is the file formatted, select "SET FIELD LENGTHS". In th enext screen set up the string with 9 character delimiters. Save it.

Now, work the data. Save it as something else.

Now, when you get a new file, name it the same, place it in th esame directory, open up the workbook, and hit F9 (refresh data).

Post back if you have different specifications (I expect the scope will expand!)

Have fun!

It's kind of fun to do the impossible! -Walter Elias Disney
Posts
7
Registration date
Wednesday November 8, 2017
Status
Member
Last seen
December 13, 2017

Hi Mark,

Thanks for replying. I am new to Macros. However let me share how exactly my data is.

Staff Name|Company|Designation|In Date|In Time|Out Date|Out Time|Staff Name|Company|Designation|In Date|In Time|Out Date|Out Time and so on.

Output i want is in another sheet.
Staff Name|Company|Designation|In Date|In Time|Out Date|Out Time
Imran Khan|Company|Designation|Date |07:00 |Date |15:30pm
Imran Khan|Company|Designation|Date |07:00 |Date |15:30pm
Imran Khan|Company|Designation|Date |07:00 |Date |15:30pm

So did you try the import?
Blocked Profile
Linear format means set delimiters. Setup the delimiters manually on the import!
Posts
7
Registration date
Wednesday November 8, 2017
Status
Member
Last seen
December 13, 2017

Hi Mark, I have recorded the below Macro. All i want is to Loop it till the last.

Sub MainTranspose()
'
' MainTranspose Macro
'
' Keyboard Shortcut: Ctrl+t
'
Sheets("Raw").Select
Selection.End(xlUp).Select
Selection.End(xlToLeft).Select
Selection.End(xlToLeft).Select
ActiveCell.Offset(1, 0).Range("Table_owssvr3[#Headers,[Name]:[Form Name]]"). _
Select
Selection.Copy
Sheets("Macro").Select
ActiveSheet.Paste
Sheets("Raw").Select
ActiveCell.Offset(0, 5).Range("Table_owssvr3[#Headers,[Name]:[CC 1]]").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Macro").Select
ActiveCell.Offset(0, 5).Range("A1").Select
ActiveSheet.Paste
ActiveSheet.Previous.Select
ActiveCell.Offset(0, 8).Range("Table_owssvr3[#Headers,[Name]:[CC 1]]").Select
Application.CutCopyMode = False
Selection.Copy
ActiveSheet.Next.Select
ActiveCell.Offset(1, 0).Range("A1").Select
ActiveSheet.Paste
ActiveSheet.Previous.Select
ActiveCell.Offset(0, 8).Range("Table_owssvr3[#Headers,[Name]:[CC 1]]").Select
Application.CutCopyMode = False
Selection.Copy
ActiveSheet.Next.Select
ActiveCell.Offset(1, 0).Range("A1").Select
ActiveSheet.Paste
ActiveSheet.Previous.Select
ActiveCell.Offset(0, 8).Range("Table_owssvr3[#Headers,[Name]:[CC 1]]").Select
Application.CutCopyMode = False
Selection.Copy
ActiveSheet.Next.Select
ActiveCell.Offset(1, 0).Range("A1").Select
ActiveSheet.Paste
ActiveCell.Offset(1, 0).Range("A1").Select
ActiveSheet.Previous.Select
ActiveCell.Offset(0, 8).Range("Table_owssvr3[#Headers,[Name]:[CC 1]]").Select
Application.CutCopyMode = False
Selection.Copy
ActiveSheet.Next.Select
ActiveCell.Select
ActiveSheet.Paste
ActiveCell.Offset(1, 0).Range("A1").Select
ActiveSheet.Previous.Select
ActiveCell.Offset(0, 8).Range("Table_owssvr3[#Headers,[Name]:[CC 1]]").Select
Application.CutCopyMode = False
Selection.Copy
ActiveSheet.Next.Select
ActiveCell.Select
ActiveSheet.Paste
ActiveCell.Offset(1, 0).Range("A1").Select
ActiveSheet.Previous.Select
ActiveCell.Offset(0, 8).Range("Table_owssvr3[#Headers,[Name]:[CC 1]]").Select
Application.CutCopyMode = False
Selection.Copy
ActiveSheet.Next.Select
ActiveSheet.Paste
ActiveCell.Offset(1, 0).Range("A1").Select
ActiveSheet.Previous.Select
ActiveCell.Offset(0, 8).Range("Table_owssvr3[#Headers,[Name]:[CC 1]]").Select
Application.CutCopyMode = False
Selection.Copy
ActiveSheet.Next.Select
ActiveSheet.Paste
ActiveCell.Offset(1, 0).Range("A1").Select
ActiveSheet.Previous.Select
ActiveCell.Offset(0, 8).Range("Table_owssvr3[#Headers,[Name]:[CC 1]]").Select
Application.CutCopyMode = False
Selection.Copy
ActiveSheet.Next.Select
ActiveCell.Select
ActiveSheet.Paste
ActiveCell.Offset(1, 0).Range("A1").Select
ActiveSheet.Previous.Select
ActiveCell.Offset(0, 8).Range("Table_owssvr3[#Headers,[Name]:[CC 1]]").Select
Application.CutCopyMode = False
Selection.Copy
ActiveSheet.Next.Select
ActiveSheet.Paste
ActiveCell.Offset(0, 8).Range("A1").Select
Selection.End(xlUp).Select
ActiveSheet.Previous.Select
ActiveCell.Offset(0, 8).Range("Table_owssvr3[#Headers,[Name]]").Select
Application.CutCopyMode = False
Selection.Copy
ActiveSheet.Next.Select
ActiveSheet.Paste
ActiveCell.Range("A1:A10").Select
Application.CutCopyMode = False
Selection.FillDown
ActiveCell.Offset(0, -1).Range("A1").Select
Selection.End(xlToLeft).Select
ActiveCell.Range("A1:E10").Select
Selection.FillDown
End Sub
Blocked Profile
Well initialize a variable, lets call it "rowscount"

Now, set the variable with a value, in this case, it will be the number of empty cells in column "A". We perform that task with the following command:
rowscount = Cells(ThisWorkbook.Worksheets("YOUR_WORKSHEET_NAME").Rows.Count, 1).End(xlUp).Row

Now, loop using the value of rowscount. You do know how to construct a loop, don't you?
Posts
7
Registration date
Wednesday November 8, 2017
Status
Member
Last seen
December 13, 2017

Dear Mark,

Thank you for replying. I am actually new to this Excel and Macro.
It's very challenging for me to do this. I got no friends or anyone in my work place to help me with this macro.
It shall be helpful, if you help me code this with the loop code.
I desperately need this as I got very less time to show case this.
Thank you in advance.
Well a standard loop based on the above example could be:

Dim rowCNT
for rowCNT = 0 to rowscount
'do your code here using the variable of rowCNT as in
msgbox(rowCNT & " of " & rowscount & " rows.")
next

Subscribe To Our Newsletter!

The Best of CCM in Your Inbox

Subscribe To Our Newsletter!