Solved

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

Posted on 2013-06-13
4
1,403 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
  • 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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
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…
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.

770 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