Solved

How to get TextBox values into Excel cells

Posted on 2001-09-11
7
208 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
  • 4
  • 3
7 Comments
 
LVL 22

Expert Comment

by:ture
Comment Utility
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
Comment Utility
...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
Comment Utility
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
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.

 
LVL 22

Expert Comment

by:ture
Comment Utility
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
Comment Utility
Great! Now you've got your points. My mistake...

bernjerg
0
 
LVL 22

Expert Comment

by:ture
Comment Utility
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
Comment Utility
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

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

Suggested Solutions

Have you ever had the experience that you had to follow 10 steps over and over again every time when you need to nicely forward an important email to your manager? Fear no more! With the help of the Quick Steps feature in Outlook 2010, your old chor…
Some time ago I was asked to create a VBA function that would calculate a check digit for an input number, using the following procedure: First, sum up all the individual digits in the number If that sum value has more than one digit, then sum up …
The viewer will learn how to make their project stand out over others by learning how to change colors and shapes, add spaces, change directions, and add bullets to their charts.
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…

743 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

12 Experts available now in Live!

Get 1:1 Help Now