+ Reply to Thread
Results 1 to 2 of 2

VBA to find blank cell then copy data next to blank cell

Hybrid View

  1. #1
    Registered User
    Join Date
    08-03-2012
    Location
    Cork Ireland
    MS-Off Ver
    Excel 2007
    Posts
    66

    Lightbulb VBA to find blank cell then copy data next to blank cell

    AS title says, i am trying to get mine working, but it doesnt seem to copy the data, here is the excerpt of my code that doesnt seem to work.

    any advice?

    Windows("Book2.xls").Activate
        Dim BCell, NBCell
        Sheets("sheet1").Range("B1").Select
        For B = 1 To 65536
        If ActiveCell.Value = Empty Then
        BCell = "B" & CStr(B - 1)
        NBCell = "B" & CStr(B - 2)
        Exit Sub
        Else
        Range("B" & CStr(B + 1)).Select
        End If
        Next B
        Range(ActiveCell.Offset(0, -1)).Select ' check with forum
        ActiveCell.Copy
        Windows("Book1.xls").Activate
        Range("A5").Select
        ActiveSheet.Paste

  2. #2
    Registered User
    Join Date
    08-03-2012
    Location
    Cork Ireland
    MS-Off Ver
    Excel 2007
    Posts
    66

    Re: VBA to find blank cell then copy data next to blank cell

    Hi chaps solved this if anyone wants to see it

    Windows("Book2.xls").Activate
        Dim BCell, NBCell
        Sheets("sheet1").Range("B1").Select
        For B = 1 To 65536
        If ActiveCell.Value = Empty Then
        BCell = "B" & CStr(B - 1)
        NBCell = "B" & CStr(B - 2)
    Range(ActiveCell.Offset(0, -1)).Select 'code should have gone here instead of at the end
        ActiveCell.Copy
        Windows("Book1.xls").Activate
        Range("A5").Select
        ActiveSheet.Paste
    
        Exit Sub
        Else
        Range("B" & CStr(B + 1)).Select
        End If
        Next B

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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