[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Find first blank column and paste copied data

Posted on 2015-01-26
4
Medium Priority
?
111 Views
Last Modified: 2015-01-27
Can an expert provide me with VBA that will find the first blank column and then paste the data I have copied

i.e. My Macro will copy data from an existing file [3columns] it will then open another file on a Sheet called Archive Daily

in this sheet I need to find the first blank column and paste the data I have copied.

Many thanks
0
Comment
Question by:Jagwarman
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 5

Accepted Solution

by:
Hakan Yılmaz earned 2000 total points
ID: 40570703
please try this.
it can look for a fixed number of adjacent blank columns, and paste your data to first cell of found range.
Sub StartCode()
    PasteToBlankColumns ThisWorkbook.Sheets("Sheet1"), 1
End Sub

Sub PasteToBlankColumns(ByRef refsheet As Worksheet, ByVal colcnt As Long)
    Dim ic As Long
    Dim checkrange As Range
    refsheet.Activate
    ic = 0
    Do
        ic = ic + 1
        Set checkrange = refsheet.Range(refsheet.Columns(ic), refsheet.Columns(ic + colcnt - 1))
        If Application.WorksheetFunction.CountA(checkrange) = 0 Then
            refsheet.Cells(1, ic).Select
            refsheet.paste
            Exit Do
        End If
    Loop
End Sub

Open in new window

0
 

Author Comment

by:Jagwarman
ID: 40572128
Hi Hakan Yılmaz I am getting an error at PasteToBlankColumns ThisWorkbook.Sheets("Sheet1"), 1

Subscript out of range (Error 9)

Regards
0
 
LVL 5

Expert Comment

by:Hakan Yılmaz
ID: 40572164
Do you have a sheet named "Sheet1"?
You can change this line with code below.
This will search blank columns in active sheet of workbook which has this code.
PasteToBlankColumns ThisWorkbook.ActiveSheet, 1

Open in new window

Or this code.
This will search blank columns in application level active sheet.
PasteToBlankColumns Application.ActiveSheet, 1

Open in new window

0
 

Author Closing Comment

by:Jagwarman
ID: 40572277
great code thanks
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question