+ Reply to Thread
Results 1 to 3 of 3

Which commands to use in a macro

Hybrid View

  1. #1
    Alok
    Guest

    Which commands to use in a macro

    Hi,

    I want to use a macro in a worksheet. In the worksheet, I have to select
    only some columns, not all. Now, the number of rows are also refreshed daily
    in that sheet.
    I have to apply conditions also in that macro for selecting the particular
    rows.
    Can I use if statement in the VB editor, and what command should i use with
    if to select a particular cell?
    Activecell?

    For example, I have to select column 3, 8 and 10 and check for all rows
    which have a value in column 5 equal to 0. Then I have to copy these rows in
    another sheet.

    Please help me out.

    Thanks in advance.


  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258
    Hello Alok,

    Do you mean that if any row in column 5 ("E") is equal to zero that columns 3, 8, and 10 ("C", "H", "J") in that same row will be copied to a another sheet?

    Sincerely,
    Leith Ross

  3. #3
    Bob Phillips
    Guest

    Re: Which commands to use in a macro

    Guessing a bit

    Sub CopyData()
    Dim oRow As Range
    Dim rng As Range
    Dim i As Long

    For Each oRow In ActiveSheet.UsedRange.Rows
    If Cells(oRow.Row, "E").Value = 0 Then
    i = i + 1
    Cells(oRow.Row, "C").Copy Worksheets("Sheet2").Range("A" & i)
    Cells(oRow.Row, "H").Copy Worksheets("Sheet2").Range("B" & i)
    Cells(oRow.Row, "J").Copy Worksheets("Sheet2").Range("C" & i)
    End If
    Next oRow
    End Sub

    --

    HTH

    Bob Phillips

    (remove nothere from the email address if mailing direct)

    "Alok" <[email protected]> wrote in message
    news:[email protected]...
    > Hi,
    >
    > I want to use a macro in a worksheet. In the worksheet, I have to select
    > only some columns, not all. Now, the number of rows are also refreshed

    daily
    > in that sheet.
    > I have to apply conditions also in that macro for selecting the particular
    > rows.
    > Can I use if statement in the VB editor, and what command should i use

    with
    > if to select a particular cell?
    > Activecell?
    >
    > For example, I have to select column 3, 8 and 10 and check for all rows
    > which have a value in column 5 equal to 0. Then I have to copy these rows

    in
    > another sheet.
    >
    > Please help me out.
    >
    > Thanks in advance.
    >




+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1