Copy Macro Required

saraapple

Board Regular
Joined
Feb 3, 2020
Messages
165
Office Version
  1. 2010
Platform
  1. Windows
I need a macro to copy the contents of a cell down until a none blank cell is met:

Stk 28.02.20 Ap.xlsx
B
5PAR-00251912
6
7
8
9
10
11
12
13
14PAR-00252030
15
16
17
18
19PAR-00251983
20
21
22
23
24
25
26
27
28
29PAR-00251982
Sheet1


Becomes:
Stk 28.02.20 Ap.xlsx
AB
51PAR-00251912
6PAR-00251912
7PAR-00251912
8PAR-00251912
9PAR-00251912
10PAR-00251912
11PAR-00251912
12PAR-00251912
13PAR-00251912
1428PAR-00252030
15PAR-00252030
16PAR-00252030
17PAR-00252030
18PAR-00252030
194PAR-00251983
20PAR-00251983
21PAR-00251983
22PAR-00251983
23PAR-00251983
24PAR-00251983
25PAR-00251983
26PAR-00251983
27PAR-00251983
28PAR-00251983
Sheet1
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
VBA Code:
Sub fill_down()

Dim x As Long, r As Long, lastRow As Long, ws As Worksheet, downTo As Long

Set ws = ThisWorkbook.Sheets("Sheet1")

With ws
    lastRow = .Cells(.Rows.Count, 2).End(xlUp).Row
    
    r = 1
    Do While r < lastRow
        downTo = .Cells(r, 1).End(xlDown).Offset(-1).Row
        If downTo > lastRow Then
            .Range(.Cells(r, 1), .Cells(lastRow, 1)).FillDown
        Else
            .Range(.Cells(r, 1), .Cells(downTo, 1)).FillDown
        End If
        r = downTo + 1
    Loop
    
End With


End Sub
 
Upvote 0
Perfect thank you.
Any idea on the next part:
Stk 28.02.20 Ap.xlsx
ABCD
1Date:28/02/20DUNELM MERIDIAN - VEHICLE DESPATCH FOR200228
2Time:13:03
3Page:1 of 14
4RTETRIPCARRIERDRIVER
51PAR-00251912DHLSTKJake Clark
6
7
8
9
10
11
12
13
1428PAR-00252030DHLSTKAndrew Bacon
15
16
17
18
194PAR-00251983DHLSTKAnna
20Goblewska
21
22
23
24
25
26
27
28
293PAR-00251982DHLSTKDaniel Embrey
30
31
32
33
34
35
36
372PAR-00251976DHLSTKJason Norcop
38
39
40Date:28/02/20DUNELM MERIDIAN - VEHICLE DESPATCH FOR200228
41Time:13:03
42Page:2 of 14
43RTETRIPCARRIERDRIVER
44
Sheet1


I need to delete the rows that contain the below in the table, but not the first occurrence of RTE?
So keep row 4 but the next time RPE appears eg. row 43 I want the row deleting.

This is all the result of a PDF converter!

Thanks

Date:
Time:
Page:
RTE
 
Upvote 0
Do you still need this? I can probably work on it later today. You basically need to use Range.Find to find the first instance of "RTE" then just loop through all the cells with a For/Next to delete rows with Date/Time/Page/RTE like you said.
 
Upvote 0
Thank you so much for taking the time to come back to me. I think I have managed to do it my macro looks like this:
Sub Macro1()
With ActiveSheet
.AutoFilterMode = False
With Range("A1", Range("a" & Rows.Count).End(xlUp))
.AutoFilter 1, "*Date:*"
On Error Resume Next
.Offset(1).SpecialCells(12).EntireRow.Delete
End With
.AutoFilterMode = False

With Range("A1", Range("a" & Rows.Count).End(xlUp))
.AutoFilter 1, "*Time:*"
On Error Resume Next
.Offset(1).SpecialCells(12).EntireRow.Delete
End With
.AutoFilterMode = False

With Range("A1", Range("a" & Rows.Count).End(xlUp))
.AutoFilter 1, "*Page:*"
On Error Resume Next
.Offset(1).SpecialCells(12).EntireRow.Delete
End With
.AutoFilterMode = False

With Range("A5", Range("a" & Rows.Count).End(xlUp))
.AutoFilter 1, "*RTE*"
On Error Resume Next
.Offset(1).SpecialCells(12).EntireRow.Delete
End With
.AutoFilterMode = False
End With
End Sub

I know it's a bit messy and should have a proper loop but it seems to work.
 
Upvote 0
Oh ok good. Hey, if it works, it works. I'm assuming you don't have to run this a million times so no biggie to have a shortcut solution. :)
 
Upvote 0

Forum statistics

Threads
1,214,904
Messages
6,122,169
Members
449,070
Latest member
webster33

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