Assign cell content to variable

Dolichotis Posted messages 42 Registration date   Status Member Last intervention   -  
Polux31 Posted messages 7219 Status Member -
Hello,

In VBA (Excel 2003), I am trying to assign the content of a cell to a variable. I tried it like this:

 Dim Type As String Type = wsExcel.Range("L" & Lig).Value


but it's not working!
If you have any solutions to propose, thank you!

Configuration: Windows 2000 Firefox 2.0.0.14

7 answers

  1. Polux31 Posted messages 7219 Status Member 1 204
     
    Hello,

    What does wsExcel represent? And Type is a reserved word in VB and VBA. Change the name of your variable.

    The following syntax works:
    Dim sType As String Dim lig As Long lig = 14 sType = worksheets("Feuil1").Range("L" & lig).Value


    ;o)

    polux
    --
    “What is well conceived can be clearly stated, And the words to say it come easily.”
    Nicolas Boileau
    1
    1. Dolichotis Posted messages 42 Registration date   Status Member Last intervention   3
       
      Hi Polux!

      Actually, I changed the name of my variable a bit before posting. And wsExcel is a sheet of a workbook (which I declared:
      Set wbExcel = ActiveWorkbook Set wsExcel = wbExcel.Worksheets("alpha")
      )
      I declared Lig as an Integer but it's a variable that changes value, it is part of a loop. Is Long preferable to Integer?


      Dim sType As String sType = wsExcel.Range("L" & Lig).Value
      0