Go Premium for a chance to win a PS4. Enter to Win

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,693 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 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

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

Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
Windows Explorer let you handle zip folders nearly as any other folder: Copy, move, change, and delete, etc. In VBA you can also handle normal files and folders, but zip folders takes a little more - and that you'll find here.
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 demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

916 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