Consulting

Results 1 to 4 of 4

Thread: Solved: Copy Data from One Sheet to another if cell is NOT empty

  1. #1
    VBAX Regular
    Joined
    Jun 2010
    Posts
    90
    Location

    Solved: Copy Data from One Sheet to another if cell is NOT empty

    Hi There,

    I have found some code to copy data from worksheet to another, however I am struggling to tweak it so that it only copies data from the cells that are not blank.

    Any ideas? Below is the code that I am trying to tweak.

     
    Sub Copy_Input_Data()
        Dim Ws1     As Worksheet
        Dim Ws2     As Worksheet
        Dim Dest    As Range
     
        Set Ws1 = Sheets("Input_Screen")
        Set Ws2 = Sheets("Live_Screen")
        Set Dest = Ws2.Range("B6").End(xlDown).Offset(1)
     
        Ws1.Range("B11:J17").Copy
        Dest.PasteSpecial xlPasteValues
        Application.CutCopyMode = False
    End Sub
    Thanks in advance

    Phil

  2. #2
    VBAX Regular
    Joined
    Jun 2010
    Posts
    90
    Location
    Bump

    Can anyone help?

    Thanks

  3. #3
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]

    Sub Copy_Input_Data()
    Dim Ws1 As Worksheet
    Dim Ws2 As Worksheet
    Dim Dest As Range
    Dim i As Long

    Set Ws1 = Sheets("Input_Screen")
    Set Ws2 = Sheets("Live_Screen")
    Set Dest = Ws2.Range("B6").End(xlDown).Offset(1)

    Ws1.Range("B11:J17").Copy
    Dest.PasteSpecial xlPasteValues
    Application.CutCopyMode = False
    For i = 7 To 2 Step -1

    If Dest.Cells(1, i - 1).Value = "" Then

    Dest.Cells(1, i - 1).Delete Shift:=xlToLeft
    End If
    Next i
    End Sub
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  4. #4
    VBAX Regular
    Joined
    Jun 2010
    Posts
    90
    Location
    Thanks xld, it works a treat =

    Thanks again for your help

Posting Permissions

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