Copy to another sheet

asdfgh

New Member
Joined
May 6, 2016
Messages
11
Hi,

I'm new to VBA and I know that this might be a big question, but here you go.

I have a sheet with data that look a bit like this and the columns continues with the next date:
A1B1C1D1E1F1G1
NameInfo1Info2Info3Info412-09-201713-09-2017....
SimonXXXXXXXX12
JohnXXXXXXXX21

<tbody>
</tbody>

I want this data to be copied in to a new sheet like this:
NameInfo1Info2Info3Info4DateData from that date
SimonXXXXXXXX12-09-20171
SimonXXXXXXXX13-09-20172
JohnXXXXXXXX12-09-20172
JohnXXXXXXXX13-09-20171

<tbody>
</tbody>

I can't figure out how to copy the first part of the row directly but 'split up' the other part. At least not in a 'simple' code.
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
asdfgh,

Here is a macro solution for you to consider that is based on your two flat screen displays, that uses two arrays in memory.

I assume that your raw data is in worksheet Sheet1, and, the results will be written to a new worksheet Results.

You can change the raw data worksheet name in the macro.

Please TEST this FIRST in a COPY of your workbook (always make a backup copy before trying new code, you never know what you might lose).

1. Copy the below code
2. Open your NEW workbook
3. Press the keys ALT + F11 to open the Visual Basic Editor
4. Press the keys ALT + I to activate the Insert menu
5. Press M to insert a Standard Module
6. Where the cursor is flashing, paste the code
7. Press the keys ALT + Q to exit the Editor, and return to Excel
8. To run the macro from Excel press ALT + F8 to display the Run Macro Dialog. Double Click the macro's name to Run it.

Code:
Sub ReorganizeData()
' hiker95, 09/12/2017, ME1022479
Application.ScreenUpdating = False
Dim w1 As Worksheet, wr As Worksheet
Dim a As Variant, lr As Long, lc As Long, n As Long, i As Long, c As Long
Dim o As Variant, j As Long, t As Variant
Set w1 = Sheets("Sheet1")   '<-- you can change the sheet name here
With w1
  lr = .Cells(Rows.Count, 1).End(xlUp).Row
  lc = .Cells(1, Columns.Count).End(xlToLeft).Column
  a = .Range(.Cells(1, 1), .Cells(lr, lc))
  n = Application.Count(.Range(.Cells(2, 6), .Cells(lr, lc)))
  ReDim o(1 To n, 1 To 7)
End With
For i = 2 To UBound(a, 1)
  For c = 6 To UBound(a, 2)
    j = j + 1
    o(j, 1) = a(i, 1): o(j, 2) = a(i, 2): o(j, 3) = a(i, 3)
    o(j, 4) = a(i, 4): o(j, 5) = a(i, 5)
    o(j, 6) = a(1, c): o(j, 7) = a(i, c)
  Next c
Next i
t = Array("Name", "Info1", "Info2", "Info3", "Info4", "Date", "Data from that date")
If Not Evaluate("ISREF(Results!A1)") Then Worksheets.Add(After:=w1).Name = "Results"
Set wr = Worksheets("Results")
With wr
  .UsedRange.Clear
  With .Cells(1, 1).Resize(, UBound(t) + 1)
    .Value = t
    .Font.Bold = True
  End With
  .Cells(2, 1).Resize(UBound(o, 1), UBound(o, 2)) = o
  .UsedRange.Columns.AutoFit
  .Activate
End With
Application.ScreenUpdating = True
End Sub

Before you use the macro with Excel 2007 or newer, save your workbook, Save As, a macro enabled workbook with the file extension .xlsm, and, answer the "do you want to enable macros" question as "yes" or "OK" (depending on the button label for your version of Excel) the next time you open your workbook.

Then run the ReorganizeData macro.
 
Upvote 0

Forum statistics

Threads
1,216,025
Messages
6,128,358
Members
449,444
Latest member
abitrandom82

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top