+ Reply to Thread
Results 1 to 7 of 7

Select empty column & paste - Help please

  1. #1
    Forum Contributor
    Join Date
    02-19-2004
    Location
    San Francisco Bay Area
    MS-Off Ver
    Microsoft 365 Aps for enterprise.
    Posts
    241

    Select empty column & paste - Help please

    Hi All,
    Here is my problem:

    I am copying a range (say A1:C150 ) then I am activating another workbook and
    selecting a sheet (sheet1) and find first empty column and paste.

    Can someone please help.

    Here is my code:

    Sub test3()
    Dim lastcolumn As Range
    Range("A1:E150").Select
    Application.CutCopyMode = False
    Selection.Copy
    Windows("DataAll.xls").Activate
    ActiveWindow.WindowState = xlNormal
    Sheets("Sheet2").Select
    ActiveSheet.lastcolumn = Cells(1, Column.count).End(xlLeft).Column
    Cells(lastcolumn + 1, 1).PasteSpecial Paste:=xlValues _
    , Operation:=xlNone, SkipBlanks:=False, Transpose:=False

    End Sub

    the above code doesn't work

    thanks
    Syed

  2. #2
    Tom Ogilvy
    Guest

    Re: Select empty column & paste - Help please

    ActiveSheet.lastcolumn = Cells(1, Column.count).End(xlLeft).Column

    should be

    ActiveSheet.lastcolumn = Cells(1, Column.count).End(xltoLeft).Column

    --
    Regards,
    Tom Ogilvy


    "saziz" <[email protected]> wrote in
    message news:[email protected]...
    >
    > Hi All,
    > Here is my problem:
    >
    > I am copying a range (say A1:C150 ) then I am activating another
    > workbook and
    > selecting a sheet (sheet1) and find first empty column and paste.
    >
    > Can someone please help.
    >
    > Here is my code:
    >
    > Sub test3()
    > Dim lastcolumn As Range
    > Range("A1:E150").Select
    > Application.CutCopyMode = False
    > Selection.Copy
    > Windows("DataAll.xls").Activate
    > ActiveWindow.WindowState = xlNormal
    > Sheets("Sheet2").Select
    > ActiveSheet.lastcolumn = Cells(1, Column.count).End(xlLeft).Column
    > Cells(lastcolumn + 1, 1).PasteSpecial Paste:=xlValues _
    > , Operation:=xlNone, SkipBlanks:=False, Transpose:=False
    >
    > End Sub
    >
    > the above code doesn't work
    >
    > thanks
    > Syed
    >
    >
    > --
    > saziz
    > ------------------------------------------------------------------------
    > saziz's Profile:

    http://www.excelforum.com/member.php...fo&userid=6350
    > View this thread: http://www.excelforum.com/showthread...hreadid=494770
    >




  3. #3
    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 Syed,

    Here is your macro re-written using object variables. This makes the code easier to read and follow. When writing code for multiple Workbooks, it is easy to lose track of what is doing what.

    Please Login or Register  to view this content.
    Sincerely,
    Leith Ross

  4. #4
    Tom Ogilvy
    Guest

    Re: Select empty column & paste - Help please

    one other typo you had:

    column.count should be columns.count

    ActiveSheet.lastcolumn = Cells(1, Columns.count).End(xltoLeft).Column

    --
    Regards,
    Tom Ogilvy



    "Tom Ogilvy" <[email protected]> wrote in message
    news:[email protected]...
    > ActiveSheet.lastcolumn = Cells(1, Column.count).End(xlLeft).Column
    >
    > should be
    >
    > ActiveSheet.lastcolumn = Cells(1, Column.count).End(xltoLeft).Column
    >
    > --
    > Regards,
    > Tom Ogilvy
    >
    >
    > "saziz" <[email protected]> wrote in
    > message news:[email protected]...
    > >
    > > Hi All,
    > > Here is my problem:
    > >
    > > I am copying a range (say A1:C150 ) then I am activating another
    > > workbook and
    > > selecting a sheet (sheet1) and find first empty column and paste.
    > >
    > > Can someone please help.
    > >
    > > Here is my code:
    > >
    > > Sub test3()
    > > Dim lastcolumn As Range
    > > Range("A1:E150").Select
    > > Application.CutCopyMode = False
    > > Selection.Copy
    > > Windows("DataAll.xls").Activate
    > > ActiveWindow.WindowState = xlNormal
    > > Sheets("Sheet2").Select
    > > ActiveSheet.lastcolumn = Cells(1, Column.count).End(xlLeft).Column
    > > Cells(lastcolumn + 1, 1).PasteSpecial Paste:=xlValues _
    > > , Operation:=xlNone, SkipBlanks:=False, Transpose:=False
    > >
    > > End Sub
    > >
    > > the above code doesn't work
    > >
    > > thanks
    > > Syed
    > >
    > >
    > > --
    > > saziz
    > > ------------------------------------------------------------------------
    > > saziz's Profile:

    > http://www.excelforum.com/member.php...fo&userid=6350
    > > View this thread:

    http://www.excelforum.com/showthread...hreadid=494770
    > >

    >
    >




  5. #5
    Forum Contributor
    Join Date
    02-19-2004
    Location
    San Francisco Bay Area
    MS-Off Ver
    Microsoft 365 Aps for enterprise.
    Posts
    241

    Tom & Leith - thank you Pls. look at the code

    Thank you both for the help.

    Actually I have a code which is working fine. But it copies a dynamic range from an active work bood and go to DataAll work book and find the last row with data and pate below it.

    Now what I wanted was to copy and go to DataAll and instead of finding an empty row, find the next empty column and paste it. I am putting my code here. i would appreciate very much if you can make it work.

    I tried Tom's changes it gives me an error 'object not defined'

    Sub mycode11()

    Dim c As Range
    Dim rRng As Range
    Dim lastRow As Long
    Dim count As Long


    'Formula Worksheets(1).Range("a2") = Mid(CELL("filename", A1), Find("]", CELL("filename", A1)) + 1, 255)
    With Worksheets(1).Range("A2").Select
    ActiveCell.FormulaR1C1 = _
    "=MID(CELL(""filename"",R[-3]C[-6]),FIND(""["",CELL(""filename"",R[-3]C[-6]))+1,FIND(""]"",CELL(""filename"",R[-3]C[-6]))-FIND(""["",CELL(""filename"",R[-3]C[-6]))-1)"

    With Worksheets(1).Range("A:A")
    Set c = .Find("Ave", LookIn:=xlValues)
    If Not c Is Nothing Then
    .Range("A1:E" & c.Row - 1).Copy
    End If
    End With

    Windows("DataAll.xls").Activate
    With Worksheets("DataAll")
    lastRow = .Range("B" & Rows.count).End(xlUp).Row (This is where I want the change from row to column)
    .Cells(lastRow + 1, 1).PasteSpecial Paste:=xlValues _
    , Operation:=xlNone, SkipBlanks:=False, Transpose:=False
    End With
    End With
    Application.CutCopyMode = False
    count = 5
    Do

    If Application.Range("B" & count) = "Orifice Axis 1" Then
    Application.Range("B" & count).Select
    Selection.EntireRow.Delete
    End If
    count = count + 1
    Loop Until Application.Range("B" & count).Value = ""

    End Sub

    Thank you
    Syed

  6. #6
    Forum Contributor
    Join Date
    02-19-2004
    Location
    San Francisco Bay Area
    MS-Off Ver
    Microsoft 365 Aps for enterprise.
    Posts
    241
    Hi Tom & Leith,
    Thank you for help. I did manage to work it out. As Tom found out some typos and I also found in Leith's code one minute thing which I was not doing right.
    In identifying columns when I wrote 'activesheet.columns.count' it worked in my code it was just columns.count.
    Its working pretty well now. thank you once again.
    Sincerely
    Syed

  7. #7
    Tom Ogilvy
    Guest

    Re: Select empty column & paste - Help please

    Dim lastCol as Long


    With Worksheets("DataAll")
    lastCol = .Range("IV" & 1).End(xltoLeft).Column
    .Cells(1,lastCol + 1,).PasteSpecial Paste:=xlValues, _
    Operation:=xlNone, SkipBlanks:=False, Transpose:=False
    End With



    --
    Regards,
    Tom Ogilvy


    "saziz" <[email protected]> wrote in
    message news:[email protected]...
    >
    > Thank you both for the help.
    >
    > Actually I have a code which is working fine. But it copies a dynamic
    > range from an active work bood and go to DataAll work book and find the
    > last row with data and pate below it.
    >
    > Now what I wanted was to copy and go to DataAll and instead of finding
    > an empty row, find the next empty column and paste it. I am putting my
    > code here. i would appreciate very much if you can make it work.
    >
    > I tried Tom's changes it gives me an error 'object not defined'
    >
    > Sub mycode11()
    >
    > Dim c As Range
    > Dim rRng As Range
    > Dim lastRow As Long
    > Dim count As Long
    >
    >
    > 'Formula Worksheets(1).Range("a2") = Mid(CELL("filename", A1),
    > Find("]", CELL("filename", A1)) + 1, 255)
    > With Worksheets(1).Range("A2").Select
    > ActiveCell.FormulaR1C1 = _
    >
    >

    "=MID(CELL(""filename"",R[-3]C[-6]),FIND(""["",CELL(""filename"",R[-3]C[-6])
    )+1,FIND(""]"",CELL(""filename"",R[-3]C[-6]))-FIND(""["",CELL(""filename"",R
    [-3]C[-6]))-1)"
    >
    > With Worksheets(1).Range("A:A")
    > Set c = .Find("Ave", LookIn:=xlValues)
    > If Not c Is Nothing Then
    > Range("A1:E" & c.Row - 1).Copy
    > End If
    > End With
    >
    > Windows("DataAll.xls").Activate
    > With Worksheets("DataAll")
    > lastRow = .Range("B" & Rows.count).End(xlUp).Row (This is where I want
    > the change from row to column)
    > Cells(lastRow + 1, 1).PasteSpecial Paste:=xlValues _
    > , Operation:=xlNone, SkipBlanks:=False, Transpose:=False
    > End WithEnd With
    > Application.CutCopyMode = False
    > count = 5
    > Do
    >
    > If Application.Range("B" & count) = "Orifice Axis 1" Then
    > Application.Range("B" & count).Select
    > Selection.EntireRow.Delete
    > End If
    > count = count + 1
    > Loop Until Application.Range("B" & count).Value = ""
    >
    > End Sub
    >
    > Thank you
    > Syed
    >
    >
    > --
    > saziz
    > ------------------------------------------------------------------------
    > saziz's Profile:

    http://www.excelforum.com/member.php...fo&userid=6350
    > View this thread: http://www.excelforum.com/showthread...hreadid=494770
    >




+ 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