#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    1
    Rep Power
    0

    How to select multiple cells of same value in VB?


    Does anyone know how I can select multiple cells (for excel) with same values in vb?

    >I need to first select cells with same value in a column, >then select the entire row and copy paste it to a new location.

    I am new to VB so any help will be greatly appreciated!

    Thanks
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    18
    Rep Power
    0

    avoid using copy / paste


    Copy/paste are basically excel functions, there is almost always an easier way in VBA

    e.g suppose you want all of the rows from "Sheet1" that have the value 7 in column A put into "Sheet2"

    sheet1row = 1
    sheet2row = 1
    sheets("sheet1").select

    with sheets("Sheet2")
    for sheet1row = 1 to 1000
    if cells(sheet1row,1) = 7 then
    for nowcol = 1 to 26
    .cells(sheet2row,nowcol) = cells(sheet1row,nowcol)
    next nowcol
    sheet2row = sheet2row+1
    end if
    next sheet1row
    end with

IMN logo majestic logo threadwatch logo seochat tools logo