Consulting

Results 1 to 5 of 5

Thread: Need Help With A Project.

  1. #1

    Need Help With A Project.

    I'm familiar with Visual Basic because I've taken classes at my school for it so i know the basic terminologies, but I have never edited a macro before and need some help.

    With that said... What I am trying to do is to take cells from a excel 2007 spreadsheet, say A1 - G1, and copy them into a .txt file. Then I need to create a loop so that it copies the next 7 columns in row 1. So What I'm trying to figgure out is how to get the text in the cell from excel to a .txt file. Also what I can't figure out is how to increase the value of the columns because they are represented by letters so I don't think I can +1 to column A.

    What may even work better is to just do 1 cell at a time, but none the less I would need to know how to increase the column letter for each pass.

    If you need any more info I will be happy to reply. Thanks in advance.

  2. #2
    VBAX Mentor MaximS's Avatar
    Joined
    Sep 2008
    Location
    Stoke-On-Trent
    Posts
    360
    Location
    you can increase columns/rows in the same time

    [VBA]Cells(i, j).Value [/VBA]

    where "i" is row number and "j" is a collumn number

  3. #3
    I'm not sure if I understand what you mean. how would i tell it to make it go from A1 to B1 for a loop?

  4. #4
    VBAX Master CreganTur's Avatar
    Joined
    Jan 2008
    Location
    Greensboro, NC
    Posts
    1,676
    Location
    Welcome to the forum- alwasy good to see new members!

    What' Maxim's trying to say is that you can use variables to stand in for your row/column values.

    I've found that I need to use the Chr() function to get columns to work correctly.

    Take the following code and paste it into a module in your workbook- be sure there are values in cells A1 and A2. After pasting in the code place your cursor anywhere in the Code and press F5 to make it run. This will grab the value of cell A1, and then increase the value of 'i' so it gets A2.

    [vba]Sub Test()
    Dim i As Integer
    Dim x As Integer
    i = 1
    x = 1
    For i = 1 To 2
    Debug.Print Range(Chr(64 + x) & 1).Value
    Next
    End Sub[/vba]

    If you want to get something from column B then you would increase the value of x.

    HTH
    -Randy Shea
    I'm a programmer, but I'm also pro-grammar!
    If your issue is resolved, please use Thread Tools to mark your thread as Solved!

    PODA (Professional Office Developers Association) | Certifiable | MOS: Access 2003


  5. #5
    VBAX Mentor MaximS's Avatar
    Joined
    Sep 2008
    Location
    Stoke-On-Trent
    Posts
    360
    Location
    loop should look like

    [VBA]Sub MyString()

    Dim MyString As String

    MyString = ""

    For j = 1 To 7
    MyString = MyString & Cells(1, j).Value & " "
    Next j
    End Sub[/VBA]


    where j = 1 to 7 means go from column A (1) to column G (7) and add values from it to make string
    looking like: "xxx xxx xxxx xxxx xxxx xxxx xxxx".

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •