Solved

How to get TextBox values into Excel cells

Posted on 2001-09-11
7
210 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
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
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
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 shows where to find the word count, how to display it, and what it breaks down to in Microsoft Word.
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…

785 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