VBA

ceytl

Board Regular
Joined
Jun 6, 2009
Messages
114
Office Version
  1. 2016
Platform
  1. Windows
Hello, I'm not sure if this is possible, but I am looking for a VBA script that can go through Column A and find the value B04.

When it finds a B04 it will go to the row below it, and if the cell is not blank, then it will copy the cell to the same row as B04, but in the next column over.

Then it would go the the next row down in Column A and see if the cell is not blank again, if it's not then it would copy it to the next column over from the last one.

This would loop until it found a blank cell, at that point it would go back to looking for the next B04 and do it over again until completed.
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Try this:
VBA Code:
Sub Test()
Dim P As Long, Lr As Long, i As Long
Lr = Range("A" & Rows.Count).End(xlUp).Row
On Error GoTo Resum1
For i = 1 To Lr
P = Range("A" & i & ":A" & Lr).Find("B04").Row + 1
If Range("A" & P).Value = "" Then Range("B" & P).Value = "B04"
i = P
Resum1:
Resume Resum2
Resum2:
Next i
End Sub
 
Upvote 0
It sertainly is possible try this:
VBA Code:
Sub test()
lastrow = Cells(Rows.Count, "A").End(xlUp).Row
inarr = Range(Cells(1, 1), Cells(lastrow + 1, 1))
For i = 1 To lastrow
  j = 1
  If inarr(i, 1) = "B04" Then
     Do While inarr(i + j, 1) <> ""
      Cells(i, j + 1) = inarr(i + j, 1)
      j = j + 1
     Loop
     i = i + j - 1
   End If
Next

End Sub
 
Upvote 0
Solution
It sertainly is possible try this:
VBA Code:
Sub test()
lastrow = Cells(Rows.Count, "A").End(xlUp).Row
inarr = Range(Cells(1, 1), Cells(lastrow + 1, 1))
For i = 1 To lastrow
  j = 1
  If inarr(i, 1) = "B04" Then
     Do While inarr(i + j, 1) <> ""
      Cells(i, j + 1) = inarr(i + j, 1)
      j = j + 1
     Loop
     i = i + j - 1
   End If
Next

End Sub

Thank you so much! It saved me hours of work!
 
Upvote 0

Forum statistics

Threads
1,214,951
Messages
6,122,442
Members
449,083
Latest member
Ava19

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