Logo 
Search:

MS Office Answers

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds
  Question Asked By: Josefina Stanley   on Nov 27 In MS Office Category.

  
Question Answered By: Edwin Chavez   on Nov 27

: Range("A2:A13").Select
: Range(Selection, Selection.End(xlToRight)).Select
: Range("A2:S13").Select
: Range(Selection, Selection.End(xlToRight)).Select
: Selection.Copy
: Sheets("DMH").Select
: Range("A2").Select
: ActiveSheet.Paste

This looks like a recorded macro. It is not necessary to do
all that selecting. This does the same thing without leaving a
copy of the range  in the clipboard.

ActiveSheet.Range("A2:S13", Range("A2:S13").End(xlToRight)).Copy _
Destination:=Worksheets("DMH").Range("A2")


: I Added this...
: 'Sheets("DMH").Select
: 'If ("d9") = "4" Then
: 'Sheets("DMH").Select
: 'Range("A63").Select
: 'ActiveSheet.Paste
: End If
:
: What I want is if in the cell  range d2:D15 if one of the cells  has a
: value(month) let's say 4(will either be month(4) or null) then I want
: to copy  the same data  to another part  of the SS, (for 4 it would be
: A63.

Loop through each cell in the range and test its value separately.

Dim rngCell As Range

With Worksheets("DMH")

For Each rngCell In .Range("d2:d15")

If rngCell.Value = 4 Then _
.Range("A2:S13", Range("A2:S13").End(xlToRight)).Copy _
Destination:=.Range("A63")

Next rngCell

End With

Share: 

 

This Question has 5 more answer(s). View Complete Question Thread

 
Didn't find what you were looking for? Find more on on If statement in a macro ? Or get search suggestion and latest updates.


Tagged: