Solved

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

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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.

705 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now