Problem with For each

  • Hi everyone,
    I have a code which copies a value from column A in one sheet, pastes it in a different sheet h30 and then prints the sheet see below. This use to work fine but now it prints 3 or 4 times even if I dont have any information in the column A of the first sheet. Anyone any ideas what is wrong, has the spreadsheet become corrupt?

    Sub c4000lc()
    For Each c In ThisWorkbook.Worksheets("4numbers").UsedRange.Columns(1).Cells
            c.Copy Destination:=ThisWorkbook.Worksheets("C4000LC").Range("h30")
            ThisWorkbook.Worksheets("C4000LC").PrintOut Copies:=1, ActivePrinter:= _
            "GlobalMark Color & Cut (Copy 2) on COM1:"
    End Sub
  • Re: Problem with For each

    I agree with pike, UsedRange can be a little unpredictable at times. How about just defining the range in column A that you want to use. Something like this perhaps:

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!