Delete Entire Row if value is not Q

S

Sean

What code could I use to Delete an entire row (move cells up) if the
value in A8:A40 is not London; New York, Paris or Berlin?

Secondly, how do I achieve a simple Copy Paste, but always 6 rows
below the last populates cell in Column A? My problem is my data
changes but I always wish to paste 6 rows below the last data.

Thanks
 
R

RichardSchollar

Hi Sean

Possibly

Sub DeleteRows()
For i = 40 to 8 Step -1
Select Case Cells(i,1).Value
Case "London","New York","Paris","Berlin"
Case Else
Rows(i).Delete
End Select
Next i
End Sub

and for the next bit:

Range("B1").Copy Destination:=Range("A65536").End(xlUp).Offset(6)

Hope this helps!

Richard
 
S

Sean

Hi Sean

Possibly

Sub DeleteRows()
For i = 40 to 8 Step -1
Select Case Cells(i,1).Value
Case "London","New York","Paris","Berlin"
Case Else
Rows(i).Delete
End Select
Next i
End Sub

and for the next bit:

Range("B1").Copy Destination:=Range("A65536").End(xlUp).Offset(6)

Hope this helps!

Richard





- Show quoted text -

Thanks Richard that seems to work a treat
 
S

Sean

One Q Richard if my Copy and Paste are on different sheets how would I
incorporate that into

Range("B1").Copy Destination:=Range("A65536").End(xlUp).Offset(6)
 
B

Bob Phillips

Worksheets("Sheet1").Range("B1").Copy Destination:= _
Worksheets("Sheet2").Range("A65536").End(xlUp).Offset(6)


--
HTH

Bob Phillips

(there's no email, no snail mail, but somewhere should be gmail in my addy)
 
S

Sean

Worksheets("Sheet1").Range("B1").Copy Destination:= _
Worksheets("Sheet2").Range("A65536").End(xlUp).Offset(6)

--
HTH

Bob Phillips

(there's no email, no snail mail, but somewhere should be gmail in my addy)








- Show quoted text -

Thanks Bob, if I was just to Paste values and Formats within the
formula how would I incorporate?

Worksheets("Sheet1").Range("B1").Copy Destination:= _
Worksheets("Sheet2").Range("A65536").End(xlUp).Offset(6)

I've tried Selection.PasteSpecial Paste:=xlPasteValues,
Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False

But not sure where to place it
 
M

Mike Fogleman

Worksheets("Sheet2").Range("A65536").End(xlUp).Offset(6).Value = _
Worksheets("Sheet1").Range("B1").Value

Mike F
 
B

Bob Phillips

No need to select

Worksheets("Sheet1").Range("B1").Copy
Worksheets("Sheet2").Range("A65536").End(xlUp).Offset(6).PasteSpecial
Paste:=xlPasteValues


--
---
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)
 
S

Sean

No need to select

Worksheets("Sheet1").Range("B1").Copy
Worksheets("Sheet2").Range("A65536").End(xlUp).Offset(6).PasteSpecial
Paste:=xlPasteValues

--
---
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)










- Show quoted text -

Bob, am I missing something her on this I'm getting a 'expected
expression' message on the very last line

Worksheets("Sheet1").Range("A1:O39").Copy Destination:= _

Worksheets("Sheet2").Range("A65536").End(xlUp).Offset(6).PasteSpecial
Paste:=xlPasteValues
 
J

JMay

Perhaps a word-wrap problem;
after typing the .PasteSpecial (alter the last character "l" a space
+
the underscore character, then the return key so that the last line(s)
look like this:

Worksheets("Sheet2").Range("A65536").End(xlUp).Offset(6).PasteSpecial _
Paste:=xlPasteValues
 
B

Bob Phillips

Post the whole code section Sean.

--
---
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)
 
S

Sean

Here it is Bob

Sub FormatArea1()
Application.ScreenUpdating = False
Sheets("Month").Activate
Cells.Select
Selection.Copy
Sheets("Area 1").Activate
Range("A1").Select
Selection.PasteSpecial Paste:=xlFormats
Selection.PasteSpecial Paste:=xlPasteValues
ActiveWindow.DisplayGridlines = False
ActiveWindow.Zoom = 75

For i = 39 To 8 Step -1
Select Case Cells(i, 1).Value
Case "City1", "City2", "City3"
Case Else
Rows(i).Delete Shift:=xlUp
End Select
Next i
Range("A1").Select


Sheets("Cumulative").Activate
Cells.Select
Selection.Copy
Sheets("Area 1").Activate

Worksheets("Cumulative").Range("A1:O39").Copy Destination:= _

Worksheets("Area1").Range("A65536").End(xlUp).Offset(6).PasteSpecial _
Paste:=xlPasteValues




For i = 66 To 34 Step -1
Select Case Cells(i, 2).Value
Case "City1", "City2", "City3"
Case Else
Rows(i).Delete Shift:=xlUp
End Select
Next i
Range("A1").Select
Sheets("Month").Activate
Range("A1").Select
End Sub
 
T

Tom Ogilvy

Worksheets("Sheet1").Range("B1").Copy
Worksheets("Sheet2").Range("A65536") _
.End(xlUp).Offset(6).PasteSpecial _
Paste:=xlPasteValues

Worksheets("Sheet2").Range("A65536") _
.End(xlUp).Offset(6).PasteSpecial _
Paste:=xlFormats
 
B

Bob Phillips

You still had a copy Destination in there with Pastespecial.

try this

Sub FormatArea1()
Application.ScreenUpdating = False
Sheets("Month").Activate
Cells.Select
Selection.Copy
Sheets("Area 1").Activate
Range("A1").Select
Selection.PasteSpecial Paste:=xlFormats
Selection.PasteSpecial Paste:=xlPasteValues
ActiveWindow.DisplayGridlines = False
ActiveWindow.Zoom = 75

For i = 39 To 8 Step -1
Select Case Cells(i, 1).Value
Case "City1", "City2", "City3"
Case Else
Rows(i).Delete Shift:=xlUp
End Select
Next i
Range("A1").Select

Sheets("Cumulative").Activate
Cells.Select
Selection.Copy
Sheets("Area 1").Activate

Worksheets("Cumulative").Range("A1:O39").Copy
Worksheets("Area1").Range("A65536").End(xlUp).Offset(6).PasteSpecial
Paste:=xlPasteValues

For i = 66 To 34 Step -1
Select Case Cells(i, 2).Value
Case "City1", "City2", "City3"
Case Else
Rows(i).Delete Shift:=xlUp
End Select
Next i
Range("A1").Select
Sheets("Month").Activate
Range("A1").Select
End Sub

--
---
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)
 
S

Sean

You still had a copy Destination in there with Pastespecial.

try this

Sub FormatArea1()
Application.ScreenUpdating = False
Sheets("Month").Activate
Cells.Select
Selection.Copy
Sheets("Area 1").Activate
Range("A1").Select
Selection.PasteSpecial Paste:=xlFormats
Selection.PasteSpecial Paste:=xlPasteValues
ActiveWindow.DisplayGridlines = False
ActiveWindow.Zoom = 75

For i = 39 To 8 Step -1
Select Case Cells(i, 1).Value
Case "City1", "City2", "City3"
Case Else
Rows(i).Delete Shift:=xlUp
End Select
Next i
Range("A1").Select

Sheets("Cumulative").Activate
Cells.Select
Selection.Copy
Sheets("Area 1").Activate

Worksheets("Cumulative").Range("A1:O39").Copy
Worksheets("Area1").Range("A65536").End(xlUp).Offset(6).PasteSpecial
Paste:=xlPasteValues

For i = 66 To 34 Step -1
Select Case Cells(i, 2).Value
Case "City1", "City2", "City3"
Case Else
Rows(i).Delete Shift:=xlUp
End Select
Next i
Range("A1").Select
Sheets("Month").Activate
Range("A1").Select
End Sub

--
---
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)












- Show quoted text -

Thanks all its working now
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top