Solved

Copying values in a textbox from one excel workbook to a different workbook with VBA

Posted on 2013-06-13
4
1,484 Views
Last Modified: 2013-06-19
I have a spreadsheet named a.xlsm which has several text boxes with data in it. I would like to copy the contents of the textboxes to another workbook named b.xlsm. So my steps are:

1) Copy data in textboxes from a.xlsm
2) open b.xlsm
3) find the next empty row in b.xlsm
4) copy data in textboxes from  a.xlsm to the next row in b.xlsm

I can't figure this out. Any help would be appreciated!
0
Comment
Question by:tkschultz1207
[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 1

Expert Comment

by:OSUK
ID: 39245638
Just to be clear are you referring to data in the cells or in textboxes embeded on the sheet?
0
 

Author Comment

by:tkschultz1207
ID: 39245665
from workbook a.xlsm I am copying data from a combination of  textboxes and cells on sheet1 to the next empty row of cells in workbook.b.xlsm
0
 
LVL 1

Accepted Solution

by:
OSUK earned 500 total points
ID: 39247989
Sorry for the delay..

The following will work for transferring the data from the cells....
Application.ScreenUpdating = False
Dim Row As Integer
Dim Col As Integer
Dim Row2 As Integer
Dim Col2 As Integer
Dim Update As Boolean
Row2 = 1
Col2 = 1
Updated = False

'Workbooks.Open ("b.xlsm")

'MsgBox 1
For Row = 1 To 10
    For Col = 1 To 10
        If Sheet1.Cells(Row, Col) <> "" Then
            Workbooks("b.xlsm").Sheets("Sheet1").Cells(Row2, Col2).Value = Sheet1.Cells(Row, Col).Value
            Col2 = Col2 + 1
            Update = True
        End If
    Next Col
        If Update = True Then
        Update = False
        Row2 = Row2 + 1
    End If
Next Row


Application.screenupdating = true

Open in new window

If the Worksheet "b" is not already open you will need to uncomment the code to open it.

If you are not sure which will be the starting cell on sheet1 on "b" then put a loop in to find it such as....
Row2 = 1
Do until Workbooks("b.xlsm").Sheets("Sheet1").Cells(Row2, Col No).Value <> ""

Row2 = Row2 + 1

Loop

Open in new window

Choosing a column that has entries in every cell.

Regarding the Textboxes, if there is not too many of them then simply use....

Workbooks("b.xlsm").Sheets("Sheet1").Cells(Row2, Col2).Value = Textbox1.Text

Open in new window


Hope this helps.
0
 

Author Closing Comment

by:tkschultz1207
ID: 39260946
Thank You so much for your help!
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

756 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