?
Solved

How to get TextBox values into Excel cells

Posted on 2001-09-11
7
Medium Priority
?
216 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 600 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
Office 365 Training for IT Pros

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

 
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

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

This article describes how to import an Outlook PST file to Office 365 using a third party product to avoid Microsoft's Azure command line tool, saving you time.
Cancel future meetings from user mailboxes in Office 365 using Remove-CalendarEvents
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

801 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