Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2013-06-13
4
Medium Priority
?
1,622 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 2000 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

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

Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
After seeing numerous questions for Dynamic Data Validation I notice that most have used Visual Basic to solve the problem. This suggestion is purely formula based and can be used in multiple rows.
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

664 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