Copy data from one sheet to another while skipping blanks and certain rows

tlc1980

New Member
Joined
Feb 13, 2013
Messages
19
Hi. I'm trying to copy data from one sheet to another, but I want it to skip blanks and a row that has data on it.

I want C9:C12, C14:C17, C19:C22, C24:C27, and C29:C34 from Sheet1 to be moved to A8:A33 on Sheet 2.

Rows 13, 18, 23, and 28 on Sheet1 need to be left out.

Thank you in advance for your help!
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
Maybe something like this...

Code:
[color=darkblue]Sub[/color] Copy_Stuff()
    [color=darkblue]Dim[/color] rng [color=darkblue]As[/color] Range, lRow [color=darkblue]As[/color] [color=darkblue]Long[/color]
    Application.ScreenUpdating = [color=darkblue]False[/color]
    [color=darkblue]For[/color] [color=darkblue]Each[/color] rng [color=darkblue]In[/color] Sheets("Sheet1").Range("C9:C12, C14:C17, C19:C22, C24:C27, C29:C34").Areas
        rng.Copy
        Sheets("Sheet2").Range("A8").Offset(lRow).PasteSpecial xlPasteValues
        [color=green]'rng.ClearContents      'Clear source data[/color]
        lRow = lRow + 5
    [color=darkblue]Next[/color]
    Application.CutCopyMode = [color=darkblue]True[/color]
    Application.ScreenUpdating = [color=darkblue]True[/color]
[color=darkblue]End[/color] [color=darkblue]Sub[/color]
 
Upvote 0
Hi! Thanks for replying. I tried out the code, but it's not showing up on Sheet2 how I want it to. Below is what my sheet looks like and how I want it to look like.

Sheet1Sheet2How I want it on Sheet2
C9Roast PorkA8Roast PorkA8Roast Pork
C10A9A9Hamburger
C11HamburgerA10HamburgerA10Steamed Brown Rice
C12A11A11Orange Glazed Sweet Potatoes
C13M/MA: [ oz] G/WG: [0/]A12A12Grapes
C14Steamed Brown RiceA13Steamed Brown RiceA13
C15A14A14
C16A15A15
C17A16A16
C18M/MA: [ oz] G/WG: [0/]A17A17
C19A18A18
C20A19A19
C21A20A20
C22A21A21
C23M/MA: [ oz] G/WG: [0/]A22A22
C24A23A23
C25A24A24
C26A25A25
C27A26A26
C28M/MA: [ oz] G/WG: [0/]A27A27
C29Orange Glazed Sweet PotatoesA28Orange Glazed Sweet PotatoesA28
C30GrapesA29GrapesA29
C31A30A30
C32A31A31
C33A32A32
C34A33A33

<tbody>
</tbody>
 
Upvote 0
Code:
[color=darkblue]Sub[/color] Copy_Stuff2()
    Application.ScreenUpdating = [color=darkblue]False[/color]
    Sheets("Sheet2").Range("A8:A33").ClearContents
    [color=darkblue]With[/color] Sheets("Sheet1").Range("C9:C12, C14:C17, C19:C22, C24:C27, C29:C34").SpecialCells(xlCellTypeConstants)
        .Copy
        Sheets("Sheet2").Range("A8").PasteSpecial xlPasteValues
        [color=green]'ClearContents      'Clear source data[/color]
    [color=darkblue]End[/color] [color=darkblue]With[/color]
    Application.CutCopyMode = [color=darkblue]True[/color]
    Application.ScreenUpdating = [color=darkblue]True[/color]
[color=darkblue]End[/color] [color=darkblue]Sub[/color]
 
Last edited:
Upvote 0
Sorry, but after playing around with it some more, I can't get it to work with my data because the cells in column c are referenced from another worksheet. I have a vlookup formula in those cells. Can you please change the code a bit to get it to work with my data? Thanks!
 
Upvote 0
Code:
[color=darkblue]Sub[/color] Copy_Stuff2()
    [color=darkblue]Dim[/color] cell [color=darkblue]As[/color] Range, r [color=darkblue]As[/color] [color=darkblue]Long[/color]
    r = 8
    Application.ScreenUpdating = [color=darkblue]False[/color]
    Sheets("Sheet2").Range("A8:A33").ClearContents
    [color=darkblue]For[/color] [color=darkblue]Each[/color] cell [color=darkblue]In[/color] Sheets("Sheet1").Range("C9:C12, C14:C17, C19:C22, C24:C27, C29:C34")
        [color=darkblue]If[/color] Len(cell) > 0 [color=darkblue]Then[/color]
            Sheets("Sheet2").Range("A" & r).Value = cell.Value
            r = r + 1
        [color=darkblue]End[/color] [color=darkblue]If[/color]
    [color=darkblue]Next[/color] cell
    Application.ScreenUpdating = [color=darkblue]True[/color]
[color=darkblue]End[/color] [color=darkblue]Sub[/color]
 
Upvote 0
Sub Copy_Stuff1()
Dim cell As Range, r As Long
r = 2
Application.ScreenUpdating = False
Sheets("Sheet4").Range("A2:A3000").ClearContents
For Each cell In Sheets("dps").Range("AHR282:AHR388, AHT282:AHT388, AHV282:AHV388, AHX282:AHX388, AHZ282:AHZ388, AIB282:AIB388, AID282:AID388, AIF282:AIF388, AIH282:AIH388, AIJ282:AIJ388, AIL282:AIL388, AIN282:AIN388, AIP282:AIP388, AIR282:AIR388, AIT282:AIT388, AIV282:AIV388, AIX282:AIX388 ")
If Len(cell) > 0 Then
Sheets("Sheet4").Range("A" & r).Value = cell.Value
r = r + 1
End If
Next cell
Application.ScreenUpdating = True
End Sub

Sub Copy_Stuff2()
Dim cell As Range, s As Long
s = 2
Application.ScreenUpdating = False

For Each cell In Sheets("dps").Range("AIZ282:AIZ388, AJB282:AJB388, AJD282:AJD388, AJF282:AJF388, AJH282:AJH388, AJJ282:AJJ388, AJL282:AJL388, AJN282:AJN388, AJP282:AJP388, AJR282:AJR388, AJT282:AJT388, AJV282:AJV388, AJX282:AJX388, AJZ282:AJZ388, AKB282:AKB388, AKD282:AKD388, AKF282:AKF388 ")
If Len(cell) > 0 Then
Sheets("Sheet4").Range("A" & s).Value = cell.Value
s = s + 1
End If
Next cell
Application.ScreenUpdating = True
End Sub

Sub Copy_Stuff3()
Dim cell As Range, t As Long
t = 2
Application.ScreenUpdating = False

For Each cell In Sheets("dps").Range("AKH282:AKH388, AKJ282:AKJ388, AKL282:AKL388, AKN282:AKN388 ")
If Len(cell) > 0 Then
Sheets("Sheet4").Range("A" & t).Value = cell.Value
t = t + 1
End If
Next cell
Application.ScreenUpdating = True
End Sub

1st thank you for the above and cool stuff 1 works but other two not working can any help me with this :confused:
 
Upvote 0
... but other two not working

"Not working" is hardly a description of the problem.
Help Us Help You

If any of the cells you want to copy have a formula that returns an error, the code (as it is now) would error on that cell. But of course, I have no idea if this is at all related to your "not working" situation.
 
Upvote 0

Forum statistics

Threads
1,221,310
Messages
6,159,176
Members
451,543
Latest member
cesymcox

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