Spending an hour+ a day copying and pasting

FBLondon

New Member
Joined
Jan 26, 2018
Messages
1
Hello,

I have a the below table with x's (only mine is 100x300).

AdamJohnFredFrank
Applesxxx
Pearsx
Bananasxxx
Grapesxx
Orangesx

<tbody>
</tbody>

I spend an hour+ each day copying and pasting into the below format by copying sheet and=IF(Sheet1!A2="x",$A1,""), remove blanks, shift up, transpose, then split out over rows.
AdamApples
AdamBananas
JohnBananas
JohnGrapes
FredApples
FrankApples
FrankPears
FrankBananas
FrankGrapes
FrankOranges

<tbody>
</tbody>


I've searched and searched online for a solution but even have trouble even describing my problem to google.

Does anyone have a better way of doing this and save my life?

Thank you in advance
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
I'm sure this is something that can be done very easily in VBA

I have to go home now and will be back in the office Monday. If you get no response by then reply in the thread and I'll help you out
 
Upvote 0
This code will do it for you. You didn't specify where you wanted the result, so I have written it out onto Sheet2
Code:
With ActiveSheet


lastrow = .Cells(Rows.Count, "A").End(xlUp).Row
lastcol = .Cells(1, .Columns.Count).End(xlToLeft).Column
inarr = Range(.Cells(1, 1), .Cells(lastrow, lastcol))


End With
With Worksheets("sheet2")
Range(.Cells(1, 1), .Cells(lastrow * lastcol, 2)) = ""
outarr = Range(.Cells(1, 1), .Cells(lastrow * lastcol, 2))
indi = 1
For i = 2 To lastcol
 For j = 2 To lastrow
   If inarr(j, i) = "x" Then
    outarr(indi, 1) = inarr(1, i)
    outarr(indi, 2) = inarr(j, 1)
    indi = indi + 1
   End If
 Next j
Next i


Range(.Cells(1, 1), .Cells(lastrow * lastcol, 2)) = outarr




End With
End Sub
 
Last edited:
Upvote 0
FBLondon,

Welcome to the MrExcel forum.

If I understand you correctly, then here is a macro solution for you to consider, that uses two arrays in memory.

With your raw data in worksheet Sheet1, the results will be written to worksheet Sheet2.


Code:
Sub ReorganizeData()
' hiker95, 01/26/2018, ME1040673
Application.ScreenUpdating = False
Dim w1 As Worksheet, w2 As Worksheet
Dim a As Variant, i As Long, c As Long, n As Long, lr As Long, lc As Long
Dim o As Variant, j As Long
Set w1 = Sheets("Sheet1")
Set w2 = Sheets("Sheet2")
With w1
  lr = .Cells(Rows.Count, 1).End(xlUp).Row
  lc = .Cells(1, Columns.Count).End(xlToLeft).Column
  n = Application.CountIf(.Range(.Cells(2, 2), .Cells(lr, lc)), "=x")
  a = .Cells(1, 1).CurrentRegion
  ReDim o(1 To n, 1 To 2)
End With
For c = 2 To UBound(a, 2)
  For i = 2 To UBound(a, 1)
    If a(i, c) = "x" Then
      j = j + 1: o(j, 1) = a(1, c): o(j, 2) = a(i, 1)
    End If
  Next i
Next c
With w2
  .Cells(1, 1).CurrentRegion.ClearContents
  .Cells(1, 1).Resize(UBound(o, 1), UBound(o, 2)) = o
  .UsedRange.Columns.AutoFit
  .Activate
End With
Application.ScreenUpdating = True
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,431
Messages
6,119,457
Members
448,898
Latest member
drewmorgan128

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