Solved

How to get TextBox values into Excel cells

Posted on 2001-09-11
7
213 Views
Last Modified: 2011-04-14
Hi!

I have an Excel spreadsheet containing a lot of textboxes. I want to extract the values in these textboxes and get them into the cells in the spreadsheet. I've tried to write a macro but it halts on the
Activecell = ActiveSheet.Shapes... line and I cannot find out what's wrong.

Dim Teller As Integer
Range("a1").Activate
For i = 116 To 228
ActiveSheet.Shapes("Rectangle " & i & "").Select

Activecell = ActiveSheet.Shapes("Rectangle " & i & "").Value

ActiveCell.Offset(0, 1).Select
Teller = Teller + 1
If Teller = 4 Then
ActiveCell.Offset(1, -4).Select
Teller = 0
End If
Next i

Can anyone help?

Regards
bernjerg
0
Comment
Question by:bernjerg
[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
  • 4
  • 3
7 Comments
 
LVL 22

Expert Comment

by:ture
ID: 6473551
bernjerg,

Try using this line of code instead:

Activecell = ActiveSheet.Shapes("Rectangle " & i & "").Characters.Text

Ture Magnusson
Karlstad, Sweden
0
 
LVL 22

Accepted Solution

by:
ture earned 150 total points
ID: 6473556
...or, if you prefer, you can use this VBA code instead of yours:

  Dim i As Integer
  Dim c As Integer
  Dim rng As Range
  Dim sh As Shape
 
  Set rng = ActiveCell
   
  For i = 116 To 228
   
    Set sh = ActiveSheet.Shapes("Rectangle " & i & "")
    rng.Value = sh.TextFrame.Characters.Text
   
    Set rng = rng.Offset(0, 1)
    c = c + 1
    If c = 4 Then
      Set rng = rng.Offset(1, -4)
      c = 0
    End If
 
  Next i

/Ture
0
 

Author Comment

by:bernjerg
ID: 6473601
Tackar s? mycket! Actually, I found it out in the meantime. By the way... Do you know a method to make Excel find the Rectangles in the spreadsheet? I tried to write "For each Rectangle In ActiveSheet" But that didn't work out.

I've increased the points to 150.

Regards
bernjerg
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 22

Expert Comment

by:ture
ID: 6473670
bernjerg,

Vars?god!

> Do you know a method to make Excel find the Rectangles in the spreadsheet?

Something like this? It finds BOTH rectangles and text boxes, which are actually the same kind of shape.

Please note that I have changed the variable name from "sh" to "shp" (to avoid confusion between shapes and sheets).

  Dim c As Integer
  Dim rng As Range
  Dim shp As Shape
 
  Set rng = ActiveCell
   
  For Each shp In ActiveSheet.Shapes
 
    If shp.AutoShapeType = msoShapeRectangle Then
   
      rng.Value = shp.TextFrame.Characters.Text
     
      Set rng = rng.Offset(0, 1)
      c = c + 1
      If c = 4 Then
        Set rng = rng.Offset(1, -4)
        c = 0
      End If
   
    End If
 
  Next shp


> I've increased the points to 150.

No, you haven't :0)

/Ture
0
 

Author Comment

by:bernjerg
ID: 6473693
Great! Now you've got your points. My mistake...

bernjerg
0
 
LVL 22

Expert Comment

by:ture
ID: 6473706
Thanks, bernjerg! I didn't know that it was possible to increase the points AFTER accepting a question. How did you do that ???

/Ture
0
 

Author Comment

by:bernjerg
ID: 6473728
I had a not updated browser window open in the background and I could increase the points from that window. I wasn't sure if you would get those points by trying to raise the points afterwards, but it seems to work just fine.

bernjerg
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

Suggested Solutions

Title # Comments Views Activity
Modify Array formula - Reduce Calculation Time 4 31
Access 2010 7 45
Pull Phone Number out of Cell 3 12
Slicers by Groups in Excel 7 20
Recently Microsoft released a brand new function called CONCAT. It's supposed to replace its predecessor CONCATENATE. But how does it work? And what's new? In this article, we take a closer look at all of this - we even included an exercise file for…
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
This video walks the viewer through the process of creating Hyperlinks for the web and other documents. Select the "Insert" tab: Click "Hyperlink":  Type "http://" followed by a web address to reference a website or navigate to a document to ref…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

733 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